# GMLCreating a direction vector from object direction

#### Dr.Spankenstein

##### Member
In order to get a vector from a direction I could do the following:

Code:
``````var dirX = dsin(direction)
var dirY = dcos(direction)``````
The problem is that this relies on

Code:
``````0 = Up
90 = Right
180 = Down
270 = Left``````
and GameMaker uses

Code:
``````0 = Right
90 = Up
180 = Left
270 = Down``````
How can I translate from gamemaker anticlockwise 90 = Up directions to the clockwise 0 = Up directions?

#### chamaeleon

##### Member
In order to get a vector from a direction I could do the following:

Code:
``````var dirX = dsin(direction)
var dirY = dcos(direction)``````
The problem is that this relies on

Code:
``````0 = Up
90 = Right
180 = Down
270 = Left``````
and GameMaker uses

Code:
``````0 = Right
90 = Up
180 = Left
270 = Down``````
How can I translate from gamemaker anticlockwise 90 = Up directions to the clockwise 0 = Up directions?
You could experiment with using the correct x/y and sin/cos combination.

• Sabnock

#### SnotWaffle Studios

##### Member
Make it negative, mod 360, add 90?

-0 mod 360 +90 = 90
-90 mod 360 + 90 = 0
-180 mod 360 + 90 = 270
-270 mod 360 + 90 = 180

You might need to do the reverse.

Edit:
This is the reverse.
So taking gamemaker's direction, just do this:
Code:
``````var newDirection = -(direction-90) mod 360;
var dirX = dsin(direction);
var dirY = dcos(direction);``````

• Dr.Spankenstein

#### Dr.Spankenstein

##### Member
Actually, that doesn't appear to handle direction = 180 correctly?

#### chamaeleon

##### Member
You do know cos is for calculating x, and sin for y, right?

#### flyingsaucerinvasion

##### Member
If I understand you, it should just be

x = dsin(angle)
y = -dcos(angle)

results in:

0: 0,-1
90: 1,0
180: 0,1
270: -1,0

#### Dr.Spankenstein

##### Member
You do know cos is for calculating x, and sin for y, right?
Ah. I'm an idiot for getting them the wrong way around! Works as expected now. Thank you, all.