Top-down movement is one of the most common systems you’ll build in GameMaker.
The goal is simple: read player input and move the character smoothly in 8 directions.
Try It Out!
Let’s build a solid, flexible version you can reuse in any project.
Step 1: Read Player Input
First, we check which directional keys are being pressed.
var move_x = keyboard_check(vk_right) - keyboard_check(vk_left);
var move_y = keyboard_check(vk_down) - keyboard_check(vk_up);
This gives us a direction vector based on input:
- Right →
(1, 0) - Left →
(-1, 0) - Down →
(0, 1) - Up →
(0, -1) - Diagonals combine naturally
Step 2: Normalize the Direction
If the player is moving, we normalize the direction so it behaves consistently in all directions.
if (move_x != 0 || move_y != 0)
{
var distance = point_distance(0, 0, move_x, move_y);
move_x /= distance;
move_y /= distance;
}
This keeps movement smooth and predictable no matter which keys are held.
Step 3: Apply Movement Speed
Now we apply speed once, using the direction we calculated.
var move_speed = 4;
x += move_x * move_speed;
y += move_y * move_speed;
That’s it! Now you’ve got clean, responsive top-down movement.
Where to Put This Code
This code typically lives in the Step Event of your player object.
Here’s the whole code just so you have it in one spot:
var move_x = keyboard_check(vk_right) - keyboard_check(vk_left);
var move_y = keyboard_check(vk_down) - keyboard_check(vk_up);
if (move_x != 0 || move_y != 0)
{
var distance = point_distance(0, 0, move_x, move_y);
move_x /= distance;
move_y /= distance;
}
var move_speed = 2;
x += move_x * move_speed;
y += move_y * move_speed;
You can also replace keyboard_check with:
- Gamepad input
- Touch controls
- AI-driven movement
The structure stays the same.
Why This Works Well
This approach:
- Scales easily to controllers and AI
- Avoids direction-based quirks
- Keeps movement logic readable and reusable
Once you’re comfortable with this setup, you can layer on:
- Collision handling
- Acceleration and friction
- Animation control
- Sprinting or dashing
Next Steps
Try extending this by:
- Limiting movement to 4 directions
- Rotating the sprite toward movement
- Adding simple wall collisions
This foundation will carry you through a lot of games.