5 minutes
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. It gets behind the ball and pushes it toward the goal. AIKick does the shooting. It picks a target and launches 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, but flipped. Its targetGoals and kick targets become RedNet. Its 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.