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

IDTitleWhat you build / learn
4.1The Enemy: Patrolgiving the enemy a body, then choosing a patrol strategy
4.2Enemy Animation: A Different State MachineDirection and Attack — and why this one never uses flipX
4.3Chase: The Aggro RadiusFindWithTag, pursuit vectors, normalized speed
4.4Attack: Close-Range Contact DamageEnter vs Stay, the damage cooldown, fairness
4.5The Full State Machine: Patrol, Chase, Attackstates, 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

← Unit 3 All units Unit 5 →