5 minutes
Add Enemy AI
For three lessons, the kilrathi has sat there. You fly circles around it and shoot off its wings, and it never fights back. A real dogfight needs the other side to fight too: the enemy ship should fly a real pattern, point its nose at you, and shoot back. The next lessons also need to know who is hostile, and matching an "enemy" string is fragile — so the game asks for a component it can query type-safely.
Make Enemy1 fly and add a second enemy
Enemy1 already has a pose, a mesh, and a kilrathi loadout from Lesson 3. To make it fly, give it the same flight stack the Player uses: Velocity6DOF, FlightIntent, and ShipFlight. Then add the brain (AiPilot), the hostile marker (Enemy), and its own MachineGun. Append these to Enemy1.components:
Now add a second fighter, Enemy2, on the same stack but spinning the other way — note the negative angularVel. Enemy1 orbits clockwise and Enemy2 counterclockwise, which spreads the pair around you instead of stacking them on one arc.
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.