RichAI velocity.magnitude returns 0 even when moving

Here are some print from an agent moving at a constant speed in a straight line:

image

Im printing this:

 public float GetSpeedPercent()
    {
        return ai.velocity.magnitude / ai.maxSpeed;
    }

Why does velocity.magnitude sometimes return 0 even when moving? It makes it impossible to use the speed to control locomotion animations.

Are you sure you are not rounding that somehow? It looks very much like an integer.

Here is the log when printing just velocity.magnitude:

image

Note that the velocity includes the y component of the velocity (i.e. gravity). For locomotion, you probably want to only use the x and z components of the velocity.

Thanks, I did try that too but doesnt fix the issue Debug.Log(new Vector3(ai.velocity.x, 0, ai.velocity.z));:

image

Its ok to make this check in Update()?

Are you sure you are not disabling/enabling the component or something?
The RichAI component typically has an acceleration and slowdown period, which I cannot see in your data.

Im just grabbing this log from when speed appears constant, acceleration seems to work fine and print what Id expect, never 0.

Might have found the issue, im setting transform.LookAt(lookAtTarget); which worked fine with Unity Navmesh agent, but seems it does something weird to RichAI, might have to set LookAt for Geometry only isntead.

1 Like

I did some investigating, and I did actually replicate this.
When a rigidbody is attached, the velocity property can get messed up.

I will include a fix for this in the next update.