Part 5: Physics, Collisions & Interactions in Godot 4
In Part 4, we built a player that moves and jumps. But right now, the world is a bit “ghostly.” There’s nothing to collect, no traps to avoid, and everything just… exists.
Reserved for AdSense Revenue
That changes today. We’re going to make our world solid and interactive.
The Two Faces of Physics
In Godot, you generally work with two types of physics objects:
- Solid Bodies: These have physical substance. They block movement (like a wall) or resolve collisions (like your player).
- Areas (Area2D): These are like “sensor zones.” They don’t block anything, but they detect when something enters them. Perfect for coins, spikes, or “level end” zones.
Collision Layers: The Radio Model
This is the concept that trips up most beginners. Think of Collision Layers and Masks like a Radio Station:
- Collision Layer: “What station am I broadcasting on?”
- Collision Mask: “What station am I listening to?”
If your Player is on Layer 2 (Player) and its Mask is set to Layer 1 (World), the player will “listen” to the world and stop at walls. If you want the player to ignore enemies, you simply tell the player’s Mask to stop listening to the Enemy layer.
Pro-Tip: You can name your layers in Project Settings > Layer Names > 2D Physics. Always name them! It’s much easier to remember “World” than “Layer 1.”
Interactive Objects: The Area2D
Let’s build a collectible coin. It shouldn’t stop the player (solid), but it needs to know when the player touches it (overlap).
Building a Coin
- Create a new scene with an Area2D root.
- Add a CollisionShape2D (Circle) and a Sprite2D.
- Attach this script:
| |
Why
queue_free()? Never usefree()to delete an object mid-game.queue_free()tells Godot: “Hey, wait until the end of this frame, then safely delete me.” It prevents your game from crashing while the physics engine is still calculating things.
Groups: Labeling Your Nodes
In the code above, we check if body.is_in_group("player"). Groups are like “tags.”
- Open your Player scene.
- Click the Node tab (next to Inspector).
- Click Groups and add a group named
player.
Now, any script in your game can easily identify the player just by checking for that tag!
Debugging: Seeing the Invisible
Collisions are invisible by default. If your player is falling through the floor, it’s hard to see why.
Go to Debug > Visible Collision Shapes in the top menu. Now, when you run your game, all your collision boxes will glow blue. This is the single most important tool for fixing physics bugs.
What You’ve Built
Take a breath and look at what you’ve accomplished:
- Part 1-2: You built a foundation and a scene.
- Part 3: You learned the “language” of GDScript.
- Part 4: You created a professional-feeling player.
- Part 5: You made a world that actually reacts to the player.
You now have a working Game Template. Everything from here—combat, inventory, levels—is just adding more “Lego bricks” to the foundation you’ve already laid.
Where to go next?
Check out our upcoming guides on AnimatedSprites to give your character a walk cycle, and TileMaps to build massive worlds in minutes!
Stay curious, and keep coding.
Reserved for AdSense Revenue
Join the Veigatec Dev Loop
Get the latest Godot, Flutter, and Web Development engineering insights delivered straight to your inbox. No fluff, just code.
We respect your privacy. Unsubscribe at any time.

