public static float LocalSideVelocity(this NavMeshAgent agent) { float magnitude = Vector3.Project(agent.GroundVelocity(), agent.transform.right).magnitude; if (magnitude < 0.1f) { return(0f); } return(magnitude * (Vector3.Dot(agent.GroundVelocity(), agent.transform.right) >= 0 ? 1f : -1f)); }