Detect the angle from Vector UP of object and the closest path node


I want to set an animation depending of current direction of object. How it will works. I run the animation and check the angle between the vectorUp of my object and direction of the neareast path. In the end of the animation, I check the angle. . If the range is change (I divide 360 degre by 8 to obtain 8 diffrent ranges with 8 diffrent animation ) i change the animation.

I know how to caluculate angle between two vectors, but i dont know how to get the closest actual path vector. Im using Simple Smooth Modifier.


You probably want to use the ai.steeringTarget property (it exists for all movement scripts).
Also checking for the angle to the up vector will not work that well for you I think. The reason is that it cannot differentiate between the character going to the right and the character going to the left (both will show up as 90 degrees). Instead I recommend you use the Mathf.atan2 method.

Thanks for your solution. You are right. Im posting my FindDegree method, maybe someone will need this

private float FindDegree(float x, float y)

  float  angleBetweenTwoPoints = (float)((Mathf.Atan2(x, y) / Math.PI) * 180f);
    if (angleBetweenTwoPoints < 0) angleBetweenTwoPoints += 360f;

    return angleBetweenTwoPoints;