• 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!

Legacy GM player movement

F

filipe

Guest
i need help with creating player movement that can turn around in a full circle and move forward in
the right direction.
i have try to do this but the turning around function and moving forward function cause the player not to move
right
here's the code
create event
Code:
image_speed = 0;
step event
Code:
if keyboard_check(vk_up)
{
image_angle+=5
if image_angle = 180
x -=3;
}

if keyboard_check(vk_down)
{
image_angle-=5
if image_angle = 180
x +=3;
}
A-key event
Code:
if keyboard_check(ord('A'))
{
image_index = 4;
y +=3;
}

if keyboard_check(vk_left)
{
y -=3;
}
D-key
Code:
if keyboard_check(ord('B'))
{
image_index = 1;
y +=3;
}

if keyboard_check(vk_right)
{
y +=3;
}
release A-key
Code:
image_index = 3;
release D-key
Code:
image_index = 1;
and here's a gif
https://gyazo.com/84d78e8645f9a18c9fb3de1b2dc8087e
as you kinda of see the movement is messed up
 

Tthecreator

Your Creator!
Look at you D-key code, you are checking for the B key instead. Also why are you using the arrow keys and A/D keys for different movements? Use either the arrow keys (vk_up, vk_down, vk_left, vk_right) or the wasd keys (ord('W'), etc). Or use them both, but not one key for the other. Unless that's a feature of your game.

Also you might want to change your =180 checks to something like this:

Code:
if keyboard_check(vk_up)
{
if image_angle>180 then{image_angle=max(image_angle-5,180)}else{
image_angle=min(image_angle+5,180)
}
if image_angle = 180
x -=3;
}
This will ensure your value will never pass 180. Right now when you reach 180 it will just continue rotating thus not executing the movement code.
This will also check the angle and pick the best turning direction.
The max/min(image_angle+/-5, 180) function is to clamp the value at 180.
The max function takes 2 input values and returns the highest value. So if one arguments was image_angle-5 and another was 180, then if image_angle-5 would get lower than 180 then the other 180 would still be higher resulting in values not being able to go below 180.
 
Top