💥 Collision Detection
5th Grade 💻 Coding
Collision detection is the check a game makes to know when two things touch: the player and a coin, the ball and a wall, the character and an enemy.
A simple way is to imagine a rectangle around each sprite and use conditions to check whether the two rectangles overlap: if the right side of one has passed the left side of the other, and they also overlap up and down, there’s a collision. Advanced games use more exact shapes, like circles or the outline of the character.
In Scratch, the work is already done for you: the sensing block “touching …?” reports true or false, and you put it inside a condition. Collision detection runs inside the game loop, every frame. When it goes wrong, characters walk right through walls, a famous bug in lots of games.
For example
- “If the ball touches the paddle, flip the ball’s direction.” That’s how a ping-pong game works.
- In a platform game, detecting a collision with the floor stops the character from falling.
📌 Remember: Collision = do the rectangles overlap? A condition checked every frame.
Quick quiz
What is collision detection?
Which Scratch block checks for a collision?
What bug comes from bad collision detection?