#Cannot set projectile velocity

36 messages · Page 1 of 1 (latest)

torpid leaf
#

I'm trying to make a projectile weapon for my game and set the velocity in the start method. For some reason, setting the velocity just doesn't work. I am setting it on the server and I know that the start method is running properly because I've used console logs to make sure. The rigidbody is getting referenced correctly. I have no idea why the velocity can't be changed.

I'll attach screenshots of my projectile class, my projectile parent class, and where I am calling the instantiation.

#

I have tried setting the owner to the local client when spawning, but that didn't change anything and also it shouldn't matter since I'm setting the velocity on the server.

quick inlet
#

This is a mess. Also post with code formatting please ```cs

#

So you're setting velocity on start, which is usually before the object is initialized over the network, then you have [Server] on that for some reason, which would block the call. You can add a Debug.Log there and see it wont fire.

#

Then your self destruct is no good, you're calling Destroy then Despawn, only call Despawn

torpid leaf
quick inlet
#

If on the server, that fires, you set the velocity and the object is not moving, then the object is probably kinematic

torpid leaf
#

It's not

quick inlet
#

If it's called on the server and on the server the object is not moving, then the object is not being simulated in physics

torpid leaf
#

It's hard for me to tell if it's firing on the server or not since I can't really log stuff from the server, but given that is has the server tag and it's running, I think it is running on the server.

quick inlet
#

What do you mean? Run in editor and start only server

#

If the logic does not work "singleplayer" then it wont work in FN either

torpid leaf
#

I can't spawn the projectile without a client to shoot it

quick inlet
#

Sure, just spawn it on the server

torpid leaf
#

I guess I could just put one in the scene and see if that works

#

Yeah, it's definitely running on the server

#

this is my rigidbody setup. It is simulated and dynamic

quick inlet
#

What's your physics set to on your TimeManager?

torpid leaf
#

TimeManager

quick inlet
#

Okay so do the test with only the server running

torpid leaf
#

I did, the Start method runs but the velocity just doesn't set

quick inlet
#

And you can tell that by reading the velocity after setting it?

torpid leaf
#

When I read the velocity it's 0. The velocity isn't being set at all

#

But the calculations are correct and when I use a Debug.Log it prints.

#

And there is a reference to the rigidbody

quick inlet
#

If you do eg rb.velocity = (0,100,0); then you print rb.velocity immediately and it does 0,0,0* then for whatever reason your object is not being simulated

torpid leaf
#

I'm not sure why though, it says it's simulated on the rigidbody

quick inlet
#

Maybe the object is being disabled or settings are changed at runtime, you can check that at runtime

torpid leaf
#

It's still all correct at runtime

quick inlet
#

Welp, open the rb example and see if that run

torpid leaf
#

It has to be something specifically about setting the forces of the rigidbody, since I can still directly set the position and it works. I have no idea why that would be a problem though, since everything is set up correctly

#

wow

#

i was using transform.forward instead of transform.up

#

welp

#

it works now lol

#

i swear i remember it being transform.forward