• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GML Creating a direction vector from object direction

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.
 
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);
 
Top