Make a 2D platformer in Godot
ActivitiesProjects
Build an original level with a controllable character, platforms and an endpoint players can reach.
Building a 2D platformer in Godot starts with getting a single character to run, fall under gravity, and jump cleanly off solid ground. A manageable first milestone keeps the scope tight—just a working movement controller and a handful of platforms—before layering on collectibles, enemies, sprite animation, or a shareable build. Working through Godot's Step by step lessons and its beginner Dodge the Creeps! tutorial (which assumes some prior programming experience) gives useful practice with project structure, movement, enemies, and scoring, though that project focuses on dodging enemies rather than platform traversal.
Coding movement, gravity, and the jump
A platformer character is typically built on a `CharacterBody2D` node moving across `StaticBody2D` surfaces. Unlike a simulated rigid body, a `CharacterBody2D` does not fall or move on its own; it detects collisions during movement, while your script calculates gravity and velocity every physics tick inside `_physics_process(delta)` and calls `move_and_slide()` so the character responds cleanly to floors and walls.
Two coordinate and logic details trip up beginners early. First, Godot's 2D coordinate system treats right and down as positive, so jumping upward requires a negative vertical velocity (a common starter setup pairs a horizontal speed of 300 with a jump velocity of -400). Second, the jump code needs to check `is_on_floor()` before applying that upward impulse; without the floor check, pressing jump repeatedly launches the character higher in midair. Once that basic loop feels predictable, you can build on it with acceleration, double jumps, or coyote time.
Input handling splits along the same line between continuous and one-shot actions. Horizontal movement is polled continuously along an axis—such as `ui_left` and `ui_right`—while jumping reacts to a discrete newly pressed `jump` action (or an `_input` event). Make sure every action name referenced in your script is actually configured in the project's input bindings for the controls you expect to use.
Building solid ground with platforms or tilemaps
Simple `StaticBody2D` blocks are enough to test running and jumping, so a tilemap is optional at first. When you want to paint larger levels on a grid, add a `TileMapLayer` node and assign it a `TileSet` built from your tilesheet.
Set the tile dimensions to match your tilesheet before generating the atlas—64 × 64 pixels is a common example, though any tile size works—so the grid slices cleanly. Painted tiles are purely visual until you add collision shapes to the ground tiles; without them, the character drops straight through the floor. Tiles can also hold occlusion and navigation shapes when needed. To keep overlapping art manageable, split foreground and background elements across separate `TileMapLayer` nodes, and save the `TileSet` as an external resource if you plan to reuse it across multiple levels.
Adding animation and collectibles
To animate the character, pair an `AnimatedSprite2D` node with a `SpriteFrames` resource loaded from either individual frame images or a sprite sheet. You define named animations such as `run`, tune their playback speed, and call `play()` or `stop()` from your movement script based on player input. Pairing `Sprite2D` with `AnimationPlayer` offers another way to drive frame animations.
Interactive pickups like coins work cleanly with an `Area2D` node and a collision shape. When the player's physics body enters that shape, the `Area2D` emits a `body_entered` signal. Connecting that signal—either in the editor or in code—to a receiver function lets you increment a score, trigger an effect, or remove the coin according to your game's rules.
Studying a fuller example and exporting a build
When you want to see how larger platformer mechanics fit together, Godot's 2D Platformer demo project—a pixel-art GDScript game with sound, keyboard and gamepad support, and a pause menu—puts an invincible player in one enclosed level with jumping, slopes, moving platforms, collectible coins, shooting, enemies, and a bounded camera. Inspecting its `level.tscn` scene and commented scripts shows practical patterns without treating every feature as required for your own project.
When your game is ready to share, add a target platform preset in the export menu and install Godot's export templates; some platforms also require extra SDKs or tools. Use Export Project to generate a runnable build—Export PCK/ZIP only packs the project data without an executable, so it will not run on its own.
