5 minutes
You can push the ball across the pitch, but nothing keeps track of who is dribbling it. A striker can't decide whether to kick until it knows one thing: does it have the ball? So every frame, something has to answer a single question. Who has the ball?
BallPossession is the answer. It is a small, pure component, and the first real game logic in this build. It draws nothing on screen. Its only output is a message sent over the bus.
Add possession to the ball
Possession belongs to the ball, so the component goes on the Ball entity:
candidateTags: ["player", "ai"] tells the System which entities to check. Every frame, it looks for anything tagged player or ai and reads its world position. Right now that is just you. The AI capsules arrive in Lesson 6, and they join the contest with no extra work. possessionDistance: 1.5 is how close you must be to claim the ball. possessionTimeout: 0.5 is the grace window.
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.