- Home /
How do I get a normalized vector2D from an angle?
How would I get a normalized vector2D from an angle? i.e. if I put in an angle of 90 I would get the vector (0,1) because it would be straight up. If I put in the angle 0 (which is to the right) I would get the vector (1,0).
Answer by NoseKills · Oct 11, 2014 at 11:51 PM
Multiply a vector by Quaternion to rotate it. Multiply a normalized vector and you'll get a normalized result.
void Start ()
{
Vector2 v1 = Quaternion.Euler(0, 0, 0) * Vector3.up;
Vector2 v2 = Quaternion.Euler(0, 0, 90) * Vector3.up;
Vector2 v3 = Quaternion.Euler(0, 0, 180) * Vector3.up;
Vector2 v4 = Quaternion.Euler(0, 0, 270) * Vector3.up;
Debug.Log(v1); //(0.0, 1.0)
Debug.Log(v2); //(-1.0, 0.0)
Debug.Log(v3); //(0.0, -1.0)
Debug.Log(v4); //(1.0, 0.0)
}
You say (1,0) is up? Normally the X axis is the horizontal one but as long as you stay true to the coordinate system you choose and choose the right kind of vector to start rotatting, you should get the results you want.
Oops! That was a typo on my part. (0, 1) is up. Also, it claims I cannot multiply a Vector and a Quaternion.
EDIT: Figured out my problem, I needed to multiply by my vector, so I could not use: Vector Quaternion; it had to be: Quaternion Vector.
Thank you for your help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613164914im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Getting the rotation of an object does not return correct rotation 1 Answer
Convert vertical angle to horizontal angle (C#) 1 Answer
Fire/Shoot at intersect point 1 Answer
Applying force with respect to angle with the ground? 1 Answer