• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Make an object move only towards image angle

W

Wyatt Johns

Guest
At the moment I have an object that moves via:

motion_add (image_angle, key_up + key_down);
//key up and down are a user input using keyboard check where up is positive and down is negitive

But I'm having an issue trying to figure out how to make the object always move towards the direction the image is facing. Basicly I would like to make it so the user pressing forward and back words sets the speed the object moves. But left and right change the direction it moves.
 
A

Aura

Guest
Speed has to be positive in order to make the instance move in image_angle direction. But since key_down can make it negative, causing it to move away instead, you should use abs() to get the absolute value.

Code:
motion_add(image_angle, abs(key_up + key_down));
 
Top