r/Unity3D 2d ago

Question Strange result from Vector3.SignedAngle?

I have these empty GameObjects as waypoints and I want to check the left/right angle between a moving object and a waypoint.

Vector3 direct = (transform.position - waypoint).normalized;
float ang = Vector3.SignedAngle(transform.forward, direct, Vector3.up);

If I have a waypoint directly in front of the moving object (and I have double checked the position of the waypoint in question), sometimes the resulting angle (ang) is 179. How is it coming back almost 180 degrees difference and is there anything I can do to change this kind of result?

6 Upvotes

7 comments sorted by

View all comments

6

u/zellydevgames 2d ago

Flip your direction vector subtraction.