Game logic
Movement and AI
How units walk, choose a target and follow the orders a mission or the player gives them.
Movement
- A unit walks its speed / 32 px per tick (its speed × 1.875 px per second), always at full speed: it does not accelerate and turns at once.
- Routes are straight lines between points, at most 56; there is no path finding. A unit pressed against an obstacle slides along it, because the game pushes it out every frame.
- It reaches each point of its route when it is less than 4.472 px away.
- Sent as a group, each unit goes to the tapped point plus its own direction from the group’s centre times its radius + 4 px. They keep no formation while walking: they only push each other apart.
Choosing a target
- Every 10 ticks (the first time staggered by the unit’s place in its squad) a unit looks for enemies less than 200 px away.
- It picks one by one of three rules: the nearest; the one with most HP; or the one with least HP. The last two prefer targets already within its attack reach.
- A charmed unit picks its target among its own side and Isaac.
- Only units in these decision states look for a new target: 0, 1, 3, 4, 5, 8, 9, and 10. Following a route without attacking, an explicit order or fleeing, they keep the one they have.
Orders
A mission or the player gives each unit an order, and the order sets the state the unit decides from every frame. The sight radius is the unit’s own (on each unit’s page), and missions often change it.
| Order | What the unit does | State |
|---|---|---|
| WaitWait | With mode 0 it stays where it is and attacks a target that comes within its reach + 22 px; it never chases. With any other mode (state 1) it chases and attacks a target within its sight radius, and otherwise idles. | 0 / 1 |
| MoveWalk · Move | Follows its route without stopping to attack. | 2 |
| Move, attacking on the wayWalkAuto · MoveAuto | Follows its route and attacks targets already within its reach, without leaving the route. | 3 |
| Move, chasingWalkAttack · MoveAttack | Chases a target within its sight radius; with none, follows its route. | 4 |
| Move, then waitWalkWaitAuto · MoveWaitAuto | Follows its route and chases targets within its sight radius; stopped and with no target, it waits as with any mode other than 0. | 5 |
| Take a crystalOccupation | Goes to the nearest mana crystal of another side within 80 px and stays until it is its side’s. With none that near, it does nothing. | 8 |
| Guard a pointGuardPosition | Watches over a point and may chase from there. Farther than its sight radius from the point, it walks back (state 10) and resumes when within half that radius. | 9 / 10 |
| FleeEscape | Runs straight away from its target while their centres are closer than its keep distance (on each unit’s page: 60 px for monsters, 0 for Isaac and the mages); then it stops. | 11 |
States 6, 7, and 12 also exist: explicit orders to attack a given unit or object, and one with no decision of its own. Which orders produce them is still being researched.
Orders in each battle
Each unit starts a battle with a list of orders, which it follows on its own, one step per tick (1/60 s). Besides the orders above, the list can hold:
back· Go back that many orders in the list, never before the first one: this is how patrols repeat.target_nearest· From then on, pick the nearest target (also: the one with most HP, the one with least HP).set_sight· Change its sight radius.change_max_hp· Change its max HP to a percentage of it; another order sets a fixed value. Both leave the list once done.
- Moves go to a point of the map, or to a point measured from where the unit stands. A move ends the tick after the unit reaches its point.
- A wait lasts its ticks; with 0 it lasts forever. Guarding never ends either: the list stays there.
- Each order starts the tick after the one before ended. When the last one ends, the unit keeps doing what it was doing.
Example: the first battle
Six Misty Mush with three quarters of their HP. The first three patrol between two points; the other three wait 2 seconds and then go from point to point, chasing whoever comes within their sight.
| Unit | Starts at | Orders |
|---|---|---|
| Misty Mush | (344, 133) |
|
| Misty Mush | (431, 78) |
|
| Misty Mush | (422, 204) |
|
| Misty Mush | (128, 82) |
|
| Misty Mush | (176, 128) |
|
| Misty Mush | (128, 174) |
|
How often the 196 battle files use each order
move_attack6268wait2983back2075move_attack(dx, dy) 515move_auto479guard367move169take_crystal156change_max_hp28move(dx, dy) 25set_sight19move_wait_auto9target_nearest6move_auto(dx, dy) 4
Read from the game’s code (the class of each order, the state it stores and the instructions that decide), not observed in an emulator.