Convert z rotation into Vector2
Hello guys, I need to convert a rotation z into Vector2.
If z = 0 => Vector2(1,0)
if z = 45 => Vector2(0.5,0.5)
if z = 90 => Vector2(0,1)
if z = -90 => Vector2(0,-1)
if z = 180 => Vector2(-1,0)
Hope you get the idea. If this function exist, please link it for me. Thanks for your time.
Answer by EvilFox · Apr 29, 2016 at 10:51 PM
Not quite, but it can be the starting point:
float fRotation = rb.rotation * Mathf.Deg2Rad;
float fX = Mathf.Sin(fRotation);
float fY = Mathf.Cos(fRotation);
Vector2 v2 = new Vector2(fY, fX);
Debug.Log(v2);
0 = 1.0, 0.0
45 = 0.7, 0.7
90 = 0.0, 1.0
-90 = 0.0, -1.0
180 = -1.0, 0.0
If you divide by Mathf.Sqrt (2.0f) you will get 0.5 at 45 degrees, but other numbers will be different.
Thanks it worked for me but i had to $$anonymous$$us rb.rotation with 90 [float fRotation = (rb.rotation - 90) * Matf.Deg2Rad]
Your answer
![](https://koobas.hobune.stream/wayback/20220612065448im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving player along a Vector 2D 0 Answers
[C#] Issue with calculating transform.position and Vector2D 1 Answer
Left hand side of an assignment must be a variable, a property or an indexer 1 Answer
What is the difference between vector2 and position? 2 Answers
I want an enemy to move around the room like a bishop, aka. diagonally. 0 Answers