5 minutes
Strikers That Attack the Goal
The midfielders chase the ball, but it stays near the centre. Nobody is trying to score yet. Chasing the ball and attacking a goal are two different jobs.
Two components give each striker that second job. AIGoalSeek does the steering, getting behind the ball and pushing it toward the goal; AIKick does the shooting, picking a target and launching the ball. Both aim at the opponent's net.
Set up the strikers
The strikers came on in Lesson 6 as plain physics bodies. Now give each one a goal to chase and a net to shoot at. The red striker attacks Blue's net. The blue striker attacks Red's:
Now set up BlueStriker the same way, flipped: targetGoals and kick targets become RedNet, avoidGoals becomes BlueNet, and teamEntities becomes ["BlueMidL", "BlueMidR"].
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.