Support Forum

Am I misunderstanding agent.velocity?

I am using the following code to calculate where an arrow should travel based on target position + target velocity:

For some reason, using IAstarAI.velocity gives incorrect results when agent is moving around in some random cases. However if I use this method I made my self it works like 99% of the time, is not IAstarAI.velocity correct in-parameter when I need the current speed of the target agent?

Custom method that works decently, but obviously not perfect since it uses maxSpeed.

 public Vector3 GetSpeed()
        Vector3 aim = agent.destination - transform.position;

        if (agent.velocity.magnitude < .1f)

        return aim.normalized * agent.maxSpeed;


agent.velocity should work fine. However, note that it includes gravity. You may want to zero out the y coordinate.

You might also be interested in