Comments and answers for "How do I translate a vector2 into one of the fixed directions"
http://answers.unity.com/questions/1648683/how-do-i-translate-a-vector2-into-one-of-the-fixed.html
The latest comments and answers for the question "How do I translate a vector2 into one of the fixed directions"Comment by rufopufo on rufopufo's comment
http://answers.unity.com/comments/1648701/view.html
Glad I helped :)Mon, 15 Jul 2019 11:08:39 GMTrufopufoComment by Nicoolai on Nicoolai's answer
http://answers.unity.com/comments/1648696/view.html
Thanks! It's so simple, I guess I was blinded by my own math-failures.Mon, 15 Jul 2019 10:58:22 GMTNicoolaiAnswer by rufopufo
http://answers.unity.com/answers/1648694/view.html
Hi there,
Firsty, you will need to see to what axis, is your vector nearer. You can achieve this, by simply comparing x and y components of your vector in absolute mode.
Example: Vector (0.3,0.7), has a greater y, so the Y axis, will be the nearest.
Vector (-0.4,0.1), has a greater x in absolute mode, so the X axis, will be the nearest.
Having this, you can handle the direction by observing the sign of your vector component.
Example: (-0.4,0.1), we had determine that X axis is the nearest, and the x component is negative. So Vector2.left will be the desired direction.
(0.3,0.7), we had determine that Y axis was the nearest, and 0.7 is positive, so the direction is upwards.
You don't have to really dive into maths, just compare the components of your vector.
Hope it helps.
If you need more help, just comment.Mon, 15 Jul 2019 10:52:29 GMTrufopufo