← Back to the map
Lesson 3

πŸ’₯ Collisions & Hitboxes

Collisions & Hitboxes illustration

Your hero can move and jump β€” but right now it would float straight through everything like a ghost. πŸ‘» A real game needs to know the exact moment two things touch: when you land on a platform, grab a coin, or bump an enemy.

The trick behind ALL of that is one simple idea: invisible boxes.

1

The big idea: everything has an invisible box

The game wraps an invisible rectangle β€” a hitboxβ€” around every single thing: your hero, each platform, every coin. It doesn't really β€œsee” the pictures; it just keeps track of these boxes.

Then, every time around the loop, it asks one tiny question over and over: do these two boxes overlap? If yes β€” touch!β€” and it runs a rule: land on the platform, collect the coin, take a hit. That's it. That one overlap check is behind almost everything that β€œhappens” in a game.

2

Your turn: see the boxes touch

Here's your hero again β€” now in a world with platforms and coins. Turn on Show the boxes and watch the hitboxes light up the instant they overlap. Land on the platforms and grab all the coins.

Click the game, then ← β†’ to move and ↑ / Space to jump. Land on the platforms and grab every coin!

πŸ“¦ Hitboxes

Every object has an invisible box. When two boxes overlap, that's a β€œtouch”.

coins collected
0 / 4
β–ΈπŸ”§ Peek inside: the coins are a β€œlist,” checked by a β€œloop”

How does the game check all four coins at once? The coins live together in a list (a row of boxes), and every single loop the game runs one rule down the whole list: β€œfor each coin, did the hero touch it?”Four coins or four hundred, it's the same one rule. Lists and loops are a huge part of how games handle lots of things at once.

🧰 Play with it in the Toolkit β†’
3

Discovery missions

Try each one, tick it off, then peek at the secret.

0/5
  • 🟫Jump up onto a floating platform. How does the hero know to STOP there instead of falling through?

  • πŸͺ™Walk into a coin. What happens the exact instant you touch it?

  • πŸ‘οΈToggle β€œShow the boxes” on and off. Are the boxes exactly the same as the pictures?

  • 🟩Stand still on a platform with the boxes shown. What colour does that platform's box turn?

  • πŸ†Collect all 4 coins.

🌟 You leveled up! You now know:

🎬 Behind the scenes β€” what's next?

Your game now has platforms, coins, and real collisions. But the hero is still just a plain red square! πŸŸ₯ Next, we turn that square into an actual character that's drawn β€” and bring it to life so it walks and jumps with real animation. πŸ‘‡

🎨Next stop Β· Lesson 4Sprites & Animation β†’Turn a little drawing into a hero that walks, jumps and comes to life.
← Back to the map