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

SOLVED Need help with character movement in a top down rpg like game.

Hello. In a game I am currently developing, I have made the character be able to move. All is working, but I was wondering if I could make it so if you hold down "shift" and press the arrow keys, it will make you walk faster. Here are the lines of code connected to the player. (the first one is a create Event, the second is a step event, the code is also in game maker language)

GML:
xspd = 0;
yspd = 0;


move_spd = 1;
GML:
right_key = keyboard_check(vk_right);
left_key = keyboard_check(vk_left);
down_key = keyboard_check(vk_down);
up_key = keyboard_check(vk_up);


xspd = (right_key - left_key) * move_spd;
yspd = (down_key - up_key) * move_spd;


//collisions
if place_meeting(x + xspd, y, obj_wall) == true
    {
    xspd = 0;
    }
if place_meeting(x, y + yspd, obj_wall) == true
    {
    yspd = 0;
    }


x += xspd;
y += yspd;
 
In the step event right after your directional input checks, you could add an input check for shift key and have it multiply/change move_spd. That should work. Pseudo code: if keyboard check shift, move_spd = 2.
 
In the step event right after your directional input checks, you could add an input check for shift key and have it multiply/change move_spd. That should work. Pseudo code: if keyboard check shift, move_spd = 2.
Thanks for the idea! I used your idea, and added this line here > "if keyboard_check(vk_shift) move_spd = 2;" and when I pressed the shift key, it changed the move speed to 2. But kept it as 2. So I then added another line "if not keyboard_check(vk_shift) move_spd = 1;" And It worked!
 
Thanks for the idea! I used your idea, and added this line here > "if keyboard_check(vk_shift) move_spd = 2;" and when I pressed the shift key, it changed the move speed to 2. But kept it as 2. So I then added another line "if not keyboard_check(vk_shift) move_spd = 1;" And It worked!
Oh yeah, I forgot that you would need to reset it! I’m glad you figured that out though.

You should also be able to use an else statement for the second part. Like this:

if shift { move speed = 2; }
else { move speed = 1; }

I think that looks better, but it is totally up to you.
 
Top