Adding Enemy AI to Your Game
Give enemies behaviour (patrol, chase, attack, give up) with a few simple states, and how to describe it to the Voidless game agent so combat feels fair and fun.
Enemies that stand still make a diorama, not a game. Even simple behaviour (patrolling, noticing the player, chasing and attacking) makes them feel like a threat. In this guide we'll cover the states most enemies need and how to ask the game agent for them.
Think in states
Most enemy behaviour is a handful of states the enemy switches between:
- Patrol: wander or walk a set path, unaware of the player.
- Chase: the player came close, so pursue them.
- Attack: in range, so strike.
- Give up: lost the player, so return.
This loop (patrol, spot, chase, attack, lose, return) already reads as intelligent behaviour.
Step 1: Animate the enemy
The behaviour decides which animation plays, so the enemy needs its set first: idle or walk, run, attack and hurt. An Animation set gives them all in one pass, matched in size.
Step 2: Describe the behaviour
In the project chat, describe it in terms of the states and the feel:
- "Slimes patrol back and forth on their platform. If the player comes within 5 tiles they chase; if the player gets 8 tiles away they go back."
- "Goblins attack when they're next to the player, with a short wind-up so the player can dodge. Use the goblin attack animation and the sword hit sound."
Step 3: Detection
The chase and give-up transition around a detection range is what makes an enemy seem aware. Ask for line of sight if walls should block it: "they only notice the player if no wall is in the way".
Step 4: Attacks that feel fair
Time the damage to the attack animation's contact frame and give a short wind-up. Pair the hit with a sound effect for impact. Then tune: too aggressive feels unfair, too passive is boring. Describe what you feel when you play and ask for changes.
Step 5: Navigation
In levels with walls, enemies need to find a way around them. Ask for pathfinding: "enemies path around walls to reach the player". (The A* guide explains how that works.)
Vary your enemies
Reuse the same behaviour with different numbers and art: a fast, weak swarmer and a slow, heavy bruiser. Recolour one sprite with the free Palette Swap tool for instant visual variants.