Game Development

GameMaker RPG Movement and Enemies for a First RPG

Build a top-down RPG player that moves and animates, then add enemies that roam, follow the player, avoid stacking, and draw in the correct order.

6 min read
A top-down game window shows a small character standing on green grass beside stone flooring and lava tiles.
A character stands in a game world with grass, stone paths, and lava tiles visible on screen. — footage: GameMaker

Start by making the room, player object, and tile-based collision layers, then code animated player movement in the Step event. Next, create a parent enemy object with variables and logic for target selection, random roaming, following the player, collision with walls and other enemies, and depth sorting by vertical position.

Set up the RPG room and project structure

First, open GameMaker and create a new project using the RPG Tutorial template. Name your project in the new project window.

GameMaker new project window showing the RPG Tutorial template selected and a project name field with text being entered.

The RPG Tutorial template is selected in the new project screen, with the project name field visible. — GameMaker

GameMaker Studio interface with the Asset Browser open to the Create Asset menu, highlighting Objects, while a pixel-art character sprite is shown in the editor.

The Asset Browser is open with Objects highlighted in the Create Asset menu, and a pixel-art character is visible in the editor. — GameMaker

To build your level:

  • Open the tile set folder and create a tile set using the provided tile set sprite.
  • The default tile size is used.

Open the default room in the Room Editor:

  • Set your background layer to the lava sprite.
  • Enable horizontal and vertical tiling on the background. Enter a low speed value (such as 0.05) in both axes for subtle movement.

Next, add two new tile layers:

  1. tiles_back (for background grass and cave tiles),
  2. tiles_col (for wall collision).

Design the walkable and blocked areas using the tile set tiles. Place collision tiles around the level edges and any walls or obstacles.

A game room editor is open with the Background layer inspector on the left and a sprite selection window showing various sprite assets, including a lava sprite.

The room editor shows the Background layer selected while the sprite picker displays the lava sprite and other asset options. — GameMaker

Finally:

  • Select the Instances layer and place obj_player in the room where you want the player to start.

file tree

Project Root
├── Sprites/
│   └── Player Sprites (idle, walk, 4 directions)
│   └── Enemy Sprites
│   └── Lava Sprite
│   └── Tile Set Sprite
├── Objects/
│   └── obj_player
│   └── obj_enemy_parent
│   └── obj_enemy_1
├── Tile Sets/
│   └── Main tile set
├── Rooms/
│   └── Main room (with background, tiles_back, tiles_col, and instances layers)

Add top-down movement and animation to the player

Add two events to obj_player: Create and Step.

GameMaker is open with the obj_player object selected and an empty code editor area in the center.

The obj_player editor is open in GameMaker with no event code shown. — GameMaker

Build enemy behavior with a parent object

Set up a parent enemy object to share movement and targeting code.

Game editor interface showing the obj_enemy_parent object editor with the Inspector panel open on the left and object properties visible.

The obj_enemy_parent object editor is open with the Inspector panel visible on the left. — GameMaker

Make enemies roam, follow the player, and avoid stacking

before after

Before

Before

// Enemy movement: only collide with walls
move_and_collide(
    h * move_speed,
    v * move_speed,
    tilemap
);
After

After

// Enemy movement: collide with walls AND other enemies
move_and_collide(
    h * move_speed,
    v * move_speed,
    [tilemap, obj_enemy_parent]
);

Sort draw order by vertical position

Add an End Step event to the player object to keep the draw order visually correct, so lower objects are drawn in front of higher ones.

The GameMaker object editor is open with a Step event showing movement code and an empty End Step event below it.

The player object editor shows the Step event code and an empty End Step event. — GameMaker

Also worth knowing

FAQ

GameMaker first RPG movement and enemies tutorial

Create your RPG structure by starting with a player object with movement and animation, then add a parent enemy object so all enemy types inherit behavior. Use tilemap collision for walls and keep all instances organized in the asset browser with clear layer setup.

how to add enemies to a GameMaker RPG

Add a parent enemy object, then create specific enemy types as children. Assign each a sprite, set values for HP, damage, and movement stats in the Inspector, give them targeting logic, and place them in the room. Make sure their movement collides with walls and other enemies.

GameMaker RPG project structure

The recommended structure includes separate folders for Sprites, Objects, Tile Sets, and Rooms. Each object and tile set is organized by type, with enemies using a parent/child hierarchy and carefully named instances and layers for easy referencing and management.

beginner GameMaker enemy behavior tutorial

Give the parent enemy object logic for both random roaming and following the player within a certain range. Call retargeting code in an Alarm event, and move each frame toward the target, clamping movement speed and handling collisions against both walls and other enemies.

GameMaker top-down RPG workflow

Begin by setting up your room and asset organization, then code player movement and animation with collision checks. Use a parent object for enemies, and sort depth after moving all instances. This workflow keeps your project organized and easily extendable as your game grows.


Official reference: GameMaker manual.

Sources

Screenshots on this page are frames from the videos below, used to illustrate the steps they describe. All rights remain with their creators.

Checked against: