Velocity.magnitude doesnt work

It return crazy figures that are all over the place. Even when the agent is stationary. Anyone found a way to find out if the agent is moving?


That seems strange. The velocity is literally just how much it has moved in the last frame divided by the current delta time.

im stop the agent from moving with canMove but the velocity.magnitude is not 0.

same here when canmove is false the velocity stops updating therefore it will get stuck at the last update number , qucik workaround is to set velocity to 0 when canmove is false

I’ve been having problems with velocity.magnitude as well. I have a RichAI component on a character and checking its velocity it returns (0.0, 0.0, 0.0) when not moving, so just as expected. When adding .magnitude though - despite still not moving - it returns different values above 0 in every update.

It seems to somehow have to do with the idle animation - at least in my case. If I default my Animator Controller to an empty state, no other changes whatsoever, then velocity.magnitude returns 0 as expected. So the slight movement of the idle animation, even though the feet don’t move on the ground, results in a tiny magnitude change. From what I could see in my tests this always is below 0.02, the highest I could see was around 0.016. Funny enough, in some super rare cases the magnitude actually returns exactly 0 but 99,9% it is slightly above.

For now I will just catch everything below 0.1 and set it to 0.

I ran into the same issue.
Any plans to fix/change this?

The AIPath and RichAI movement scripts may return values above zero, but very close to zero. I’d recommend check if the the speed is below some small threshold, not exactly zero.

The new FollowerEntity movement script in the beta will go to a velocity of exactly zero, though (at least as long as local avoidance is not used).

maybe i am doing something wrong, but when i set “can move” to false the magnitude is and stays: 10.81653
I even do this before the “false” set: RichAI.velocity.Set(0,0,0);
Velocity value is: (-6.52, -3.41, 8.56)

Setting canMove to false will disable the agent’s movement calculations completely. This includes the code that updates the velocity. You may instead want to use e.g. isStopped.