# How can I get a direction vector from a an Euler angle?

Im trying to get a directional vector from an euler angle. But im not getting how to do it. This is what i got so far.

escapeAngle += 90;
var radians = escapeAngle * (Mathf.PI / 180);

var escapeAngleAsDirectionVector = new Vector2 ();

escapeAngleAsDirectionVector = transform.TransformPoint (escapeAngleAsDirectionVector);

• What do you get? What did you expect to get? – occulus Apr 16 '14 at 13:52
• I dont know what to expect more than a vector2 that Points in the direction of the angle. What i get is direction vector pointing in weird angles that is not the angle i provided. – Daarwin Apr 16 '14 at 14:59
• Then edit your question and put that in your question please! – occulus Apr 16 '14 at 15:16
• Can you give a few examples of what you're putting in and what you are getting as a result? First, you are adding 90 degrees so you are supposed to get a perpendicular vector of course. – wolfdawn Apr 17 '14 at 4:19
• First thing is you shouldn't be adding 90 to the angle, unless you want a perpendicular vector rather than one facing in the same direction. – CoffeeandCode Apr 17 '14 at 13:06

You can create a rotation quaternion from your Euler angles. By multiplying it with a vector 'right', you get a Vector2:

Vector2 v = Quaternion.Euler(x, y, z) * Vector2.right

• also most probably, z = watever, like 0, should yield the same results. you need only 2 angles for a direction. – v.oddou Oct 15 '14 at 1:55

The correct formula is V = {r*cos(theta), y*sin(theta)} to get a vector from an angle with line at angle theta of length r, so your calculations look right. BUT one thing you need to account for is if the angle is negative. then you would have to add 360 to the angle.

E.g.

if(esacapeAngle < 0)
escapeAngle += 360;


Another thing you should probably check if the angle is greater than or equal to 360 after the addition, because that wouldn't be valid either.

if(escapeAngle >= 360)
throw error


then do the rest of your calculations.

This will give you a perpendicular vector though, as you add 90 to the angle.

Converting Polar coordinates to Cartesian coordinates