Play Game Design · Godot Basics · 5 of 10

Collisions & physics bodies

Make things solid. You'll learn which node to use for walls, players and pickups, turn your Godot logo into a real player that walls can stop, and finally collect your spinning coins.

⏱ About 25 minutes✅ Needs Basics 4
0 of 4 complete
1

Feel it: what's solid?

Drive the yellow player into each object. Each one is a different kind of node, and each reacts differently.

Click to playMove with WASD or the arrow keys
Mission
    2

    Name it

    Every physical thing in Godot is a body or an area, plus a shape.

    CollisionShape2D

    No shape, no collision

    Bodies and areas don't know how big they are until they get a CollisionShape2D child with a shape. Without it, things pass straight through, exactly like when you unticked the box above.

    StaticBody2D

    🧱 Solid, never moves

    Walls, floors and platforms. Other bodies bump into it and stop.

    CharacterBody2D + move_and_slide()

    🏃 Solid, moved by your code

    Set its velocity, then call move_and_slide(). Godot moves it, stops it at walls and slides it along them. It also handles delta for you.

    Area2D

    👻 Not solid, but notices

    Things pass through it, and it can tell when they're inside. Perfect for coins, spikes and checkpoints. has_overlapping_bodies() asks “is any body touching me right now?”

    Also new: _physics_process(delta) works like _process, but runs at a steady 60 times a second, in step with Godot's physics. Use it for anything that moves with physics. And queue_free() removes a node from the game safely.
    3

    Prove it: fix the broken level

    Three objects in this level are set up wrong. Select each one, fix its type or shape in the mini Inspector, then play to test.

    Click to test the levelWASD or arrow keys
    Goals

      Scene dock

      Inspector

      4

      Build it in Godot: a real player, walls and collecting

      About 15 minutes. Keep working in your project from Basics 4.

      Part A: the player scene

      1. New scene. Scene → New Scene. In the empty Scene dock, click Other Node. In the Create New Node window, search CharacterBody2D, select it, click Create, and rename it Player.Check: blue icon, and the Inspector shows CharacterBody2D, Node2D and Transform. White circle? Right-click → Change Type…Save it right away: press Ctrl+S (Cmd+S on Mac), name it player.tscn and click Save. You only name it once: from now on, Ctrl+S saves straight into player.tscn. Save after every step.
      2. Give it a look. With Player selected, click + (top left of the Scene dock) → Sprite2D. Drag icon.svg from the FileSystem dock onto its Texture field. Set Transform → Scale to 0.4, 0.4. 💾 Save: Ctrl+S
      3. Give it a shape. Click Player, then + → CollisionShape2D. In the Inspector, click <empty> next to Shape → RectangleShape2D. Click the word RectangleShape2D to expand it and set Size to 50 and 50.The blue outline should roughly cover the logo, and the yellow ⚠ disappears. 💾 Save: Ctrl+S
      4. Attach a script. Select Player → Attach Script button (scroll with green +). Check Inherits says CharacterBody2D and the path ends in player.gd. Click Create. Select all the code (Ctrl+A) and replace it with:
        Notice there's no * delta this time: velocity is already “pixels per second,” and move_and_slide() handles the timing. It uses the move actions you made in Basics 4.
      5. Save (Ctrl+S), then click 2D at the top.

      Part B: a reusable wall

      1. New scene. Scene → New Scene → Other Node → StaticBody2D → Create. Rename it Wall.Save it right away: press Ctrl+S, name it wall.tscn, click Save. You only name it once: every Ctrl+S after this saves straight into wall.tscn. If a “Save Scene As” window ever pops up again, the scene wasn't saved yet, so name it wall.tscn then.
      2. Make it visible. Click Wall in the Scene dock, then + → search ColorRect → Create. A tiny box appears in the viewport. In the Inspector, open Layout → Transform: Size 64, 64, Position -32, -32. Set Color to hex 3A3F6B (click the color box, type it in the Hex field, press Enter). 💾 Save: Ctrl+S
      3. Make it solid. The wall can be seen now, but the player could walk right through it. It needs a shape: ① Click Wall in the Scene dock (the top node, not ColorRect), so the new node becomes Wall's child.
        ② Click +, search CollisionShape2D and click Create. A yellow ⚠ appears next to it, which is normal for now.
        ③ In the Inspector, find Shape, click the <empty> box next to it and pick RectangleShape2D.
        ④ Click the word RectangleShape2D to expand it, and set Size to 64 (x) and 64 (y).
        Check: the Scene dock shows Wall with two children, ColorRect and CollisionShape2D. The blue outline covers the dark square exactly, and the yellow ⚠ is gone. 💾 Save: Ctrl+S

      Part C: put it together

      1. Open the main scene. Click the main tab above the viewport, or double-click main.tscn in the FileSystem dock.
      2. Retire the old logo. In the Scene dock, right-click Icon (the logo you drove around in Basics 4) → Delete Node(s) → confirm. The new Player replaces it.Its mover.gd script stays in the FileSystem, unused. That's fine. 💾 Save: Ctrl+S
      3. Add the player. Drag player.tscn from the FileSystem dock into the viewport, inside the purple rectangle. Then set its Position to 150, 320 in the Inspector. 💾 Save: Ctrl+S
      4. Add walls. Drag wall.tscn into the viewport 5 times and arrange them into obstacles, like a short barrier or a corner. Keep them away from your coins.Press Q for Select mode to drag them, or type Positions in the Inspector. 💾 Save: Ctrl+S
      5. Teach coins to get collected. Click the coin tab above the viewport. In the Scene dock, click the scroll icon next to Coin. That opens coin.gd directly in the Script view.Make sure it's the right script. The Script view lists every script you've opened on its left side (player.gd, mover.gd, main.gd…). Check that coin.gd is the highlighted one and the first line says extends Area2D. If not, click coin.gd in that list.Then select all (Ctrl+A) and replace it with this. It's your Basics 3 script plus three new lines at the bottom:
        💾 Save: Ctrl+S
      6. Save everything. Press Ctrl+S in the script, then use Scene → Save All Scenes. Click 2D, open the main tab, and press F6. Click inside the game window and drive around.

      💾 Save before you run. A (*) on a tab means unsaved changes, which may not show up in the game.

      🛠 Common problems
      The player walks straight through the walls

      One of the two is missing its shape. Open wall.tscn and player.tscn and check each CollisionShape2D has a RectangleShape2D (no yellow ⚠). Also check player.gd uses velocity and move_and_slide(); the old Basics 4 code moved with position +=, which ignores walls.

      A coin disappears the moment the game starts

      It's touching a wall. Walls are bodies too, so the coin thinks it was collected. Move the coin or the wall apart. (Basics 6 shows how to make coins react only to the player.)

      Coins don't disappear when I touch them

      Check the coin's CollisionShape2D has a CircleShape2D, that you saved the coin script, and that the three new lines are indented with one Tab, inside _process.

      The player doesn't move

      Click inside the game window first. Check the move actions from Basics 4 exist (Project → Project Settings → Input Map), and that player.gd is attached to Player in player.tscn. A scroll icon should be next to it.

      There are two logos, and one of them drives through walls

      You still have the old Icon in main.tscn. Delete it (step 12).

      Error: “Mixed use of tabs and spaces”

      Select all the code and use Edit → Indentation → Convert Indent to Tabs in the script editor.

      Checkpoint

      Your logo drives around with WASD or the arrows, stops against walls and slides along them. Touching a coin makes it vanish, and the Output panel prints “Coin collected!”

      🎯 Your turn optional · no code given

      Build a spike trap

      Add a red square to your level that restarts the level when the player touches it. It shouldn't block the player, just punish them.

      Done when touching the red square instantly resets the level: the player goes back to the start and the collected coins come back.

      You'll need: a new scene (like your wall and coin), the right root node, and one new function: get_tree().reload_current_scene(), which restarts the level.

      💡 Hint 1 (a nudge)

      It doesn't block, but it notices the player. That's the same kind of root node as your coin. Build the scene the same way you built the wall: a root, something to see, and a shape.

      💡 Hint 2 (more help)

      Make a new scene: Area2D root named Spikes, a red ColorRect (Size 64, 64, Position -32, -32) and a CollisionShape2D with a RectangleShape2D (64, 64). Attach a script, and every physics frame check has_overlapping_bodies(). If it's true, reload the scene. Save as spikes.tscn and drag it into main.tscn.

      ✅ Solution (try it yourself first!)
      extends Area2D
      
      func _physics_process(_delta: float) -> void:
      	# Is anything (like the player) touching the spikes?
      	if has_overlapping_bodies():
      		get_tree().reload_current_scene()

      The underscore in _delta tells Godot “I know I'm not using this,” which hides a yellow warning. Keep spikes away from walls: walls are bodies too, so a wall touching the spikes would restart the level forever.

      5

      Quick check

      Three questions, then you're done.

      🎉 Your game has rules now.

      You know which body to use for what, why shapes matter, and how move_and_slide keeps your player out of walls. Your coins can be collected, too.

      Next · Basics 6: Signals
      Let the coin tell the score it was collected, the clean way
      Start Basics 6 →