- Home /
How to calculate order of directions relative to world forward around point?
I need to work out how to order a list of directions in a clockwise order around a point. This should start from the world forward point as a reference/cutoff.
This illustration shows how the directions should be ordered - in a clockwise direction. I already have this working to some degree however it presents some issues when the two directions are parallel.
Quaternion.FromToRotation(Vector3.forward, directionX).eulerAngles.y;
Then put the results into an ordered list using the key as the Y value. If anyone has other methods it would be very helpful.
Answer by Bunny83 · Jun 07, 2018 at 04:25 PM
You can simply use the Vector3.SignedAngle method. Just pass your forward direction, your direction you want to test and your up direction. It will give you a signed angle that you can use to order the directions. To get an angle in the range of 0 to 360 you would do
float angle = Vector3.SignedAngle(transform.forward, dir, transform.up);
if (angle <0)
angle +=360;
Your answer
![](https://koobas.hobune.stream/wayback/20220612164317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotate object based on hit normal + matching camera direction 0 Answers
Rotating a direction Vector3 by Quaternion 2 Answers
Get rotation from a vector direction. 1 Answer
Slerp look at direction not working... 3 Answers
Snap a direction vector 1 Answer