Unit 4 — The Enemy
A hunter with a memory: patrol, chase, attack, return. The unit ends with the full state machine drawn on paper and named in code — the biggest AP-algorithm idea of the semester, hidden in a guard with a leash.
Lessons
| ID | Title | What you build / learn |
|---|---|---|
| 4.1 | The Enemy: Patrol | giving the enemy a body, then choosing a patrol strategy |
| 4.2 | Enemy Animation: A Different State Machine | Direction and Attack — and why this one never uses flipX |
| 4.3 | Chase: The Aggro Radius | FindWithTag, pursuit vectors, normalized speed |
| 4.4 | Attack: Close-Range Contact Damage | Enter vs Stay, the damage cooldown, fairness |
| 4.5 | The Full State Machine: Patrol, Chase, Attack | states, transitions, selection — drawn and named |
Concepts this unit owns
The state machine pattern, normalized vectors, and the exam's algorithm definition — sequencing, selection, iteration — built from nothing in EnemyController.cs, then upgraded from implicit conditions to named states. Along the way you learn to read a state machine somebody else assembled, because this project's enemy animator disagrees with the player's on almost every convention. CED: AAP-1, AAP-2, AAP-3 (all three, in one script).
Reference docs in this unit
- Enemy State Machines — the full pattern reference, boss edition included