Before being passed in, the X and Y directions are multiplied by my_speed, which we defined in the Create event
Run the game and you have movement!
To WASD keys instead of arrow keys, replace the vk_* etc. constants with:
vk_left -> ord(“A”)
vk_right -> ord(“D”)
vk_up -> ord(“W”)
vk_down -> ord(“S”)
You can also use both arrow keys and WASD at the same time, by joining them with ‘or’ e.g. (keyboard_check(vk_left) or keyboard_check(ord(“A”)).
Limiting Movement
If you try to move diagonally (e.g. hold both right and down at the same time) and slide along a wall, you’ll notice the player moves faster than it normally would.
You can fix this by setting a limit on how fast the player can move on any axis. This is set in the last two arguments of move_and_collide().
I’ll change my move_and_collide() line/action to this:
The initial three (4, 0, 0) are arguments I don’t want to change, so I’ve passed in their default values as per the manual.
The last two arguments are the X and Y speed limits of the player. I’ve passed in my_speed for both.
Now, the player won’t move faster when moving diagonally while sliding along walls.
Shape Collisions
This function supports collisions for sprites of any shape – e.g. ellipse, diamond and precise shapes:
Using an ellipse shape for my player
Using a precise shape for this diagonal wall
Throw these shapes into the game and they will work perfectly:
Invisible Objects
If you’re primarily using tiles for your environment, you can still continue to use objects such as obj_wall for collisions. Just make the object invisible:
Place your wall instances in your room to cover your tiles. These will continue to work in the game, but won’t be visible to the player.