In this guide you build Coin Rush: move a character around the screen and grab as many coins as you can in 30 seconds. It's small on purpose. By the end you'll have used the ideas every Godot game is made of: scenes, nodes, scripts, input, collisions, signals and a game loop, and you'll have a version you can share as a link.
New to engines? Read Godot vs Unity vs Unreal first, then come back.
1. Install Godot and create the project
- Download Godot 4 (the standard version, not the .NET one) from godotengine.org. There's nothing to install: unzip it and run it.
- Click Create, name the project
coin-rush, and pick the Compatibility renderer. It runs on older computers and is the renderer Godot uses for web exports.
Godot projects are built from scenes, and scenes are trees of nodes. A node is one thing with one job: a sprite draws an image, a collision shape defines a hitbox, a timer counts down. You'll make three scenes: a player, a coin and the main level.
2. The player
- Create a new scene. Choose Other Node and add a CharacterBody2D. Rename it
Player. - Add a Sprite2D child and drag
icon.svgfrom the FileSystem panel into its Texture. This placeholder is fine for now. - Add a CollisionShape2D child, set its Shape to a new RectangleShape2D, and resize it to cover the sprite.
- In the Node panel, open Groups and add the player to a group called
player. The coin will use this to recognise it. - Save the scene as
player.tscn, then attach a script toPlayer(player.gd):
extends CharacterBody2D
const SPEED := 300.0
func _physics_process(_delta: float) -> void:
# Arrow keys are mapped to the built-in ui_* actions.
var direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
velocity = direction * SPEED
move_and_slide()
# Keep the player on screen.
position = position.clamp(Vector2.ZERO, get_viewport_rect().size)
Input.get_vector turns four directions into one vector, so diagonal movement isn't faster than straight movement. move_and_slide moves the body and handles collisions for you, and Godot already scales it by the frame time. (Our game loop guide explains why that matters.)
3. The coin
- Create a new scene with an Area2D root called
Coin. Areas detect overlaps without blocking movement, which is exactly what a pickup needs. - Add a Sprite2D with
icon.svgand set its Scale to0.4so it looks different from the player. Add a CollisionShape2D with a CircleShape2D. - Save it as
coin.tscnand attachcoin.gd:
extends Area2D
signal collected
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player"):
collected.emit()
queue_free()
- Select
Coin, open the Node panel, double-click the body_entered signal and connect it to_on_body_enteredin the coin script.
A signal is a message: the coin announces "I was collected" without needing to know who keeps score. That keeps scenes independent and easy to reuse.
4. The main scene and the rules
- Create a scene with a Node2D root called
Main. Dragplayer.tscninto it and move the player to the middle of the screen. - Add a Label child, place it in the top-left corner, and give it a large font size in Theme Overrides.
- Save it as
main.tscn, set it as the main scene (Project → Project Settings → Application → Run → Main Scene), and attachmain.gd:
extends Node2D
const COIN_SCENE := preload("res://coin.tscn")
const ROUND_SECONDS := 30.0
var score := 0
var time_left := ROUND_SECONDS
var game_over := false
@onready var player: CharacterBody2D = $Player
@onready var label: Label = $Label
func _ready() -> void:
for i in 8:
spawn_coin()
func spawn_coin() -> void:
var coin := COIN_SCENE.instantiate()
var size := get_viewport_rect().size
coin.position = Vector2(randf_range(40, size.x - 40), randf_range(80, size.y - 40))
coin.collected.connect(_on_coin_collected)
add_child(coin)
func _on_coin_collected() -> void:
score += 1
spawn_coin()
func _process(delta: float) -> void:
if game_over:
if Input.is_action_just_pressed("ui_accept"):
get_tree().reload_current_scene()
return
time_left = max(time_left - delta, 0.0)
label.text = "Coins: %d Time: %d" % [score, int(ceil(time_left))]
if time_left == 0.0:
game_over = true
player.set_physics_process(false)
label.text = "Time's up! You got %d coins. Press Enter to play again." % score
Press F5 to play. Every coin you grab spawns a new one somewhere random, the timer counts down, and when it hits zero the player freezes until you press Enter.
5. Make it feel like a game
Small touches make a big difference. Try one at a time:
- Real art: swap
icon.svgfor sprites from a free pack (see free game art, sound and music). - Sound: add an AudioStreamPlayer to the coin and play it in
_on_body_enteredbeforequeue_free()(or let Main play it, since the coin is deleted immediately). - A best score: keep the highest score in a variable on an autoload, or save it to a file.
- Juice: a little scale "pop" when a coin is collected. Our guide to game feel has more ideas.
6. Share it as a link
- Open Editor → Manage Export Templates and download the templates for your Godot version.
- Open Project → Export, add a Web preset, and export to an empty folder as
index.html. - Zip the contents of that folder (not the folder itself) and upload it to itch.io as an HTML game. Our guide to publishing on itch.io walks you through it.
The default web export is single-threaded, which runs on itch.io without extra server settings. One limit to know: Godot 4 projects written in C# can't export to the web yet, which is one more reason to start with GDScript.
What we learned shipping our first Godot games
Merge 2048 was our first Godot game and Tank Arcade one of the next. Three things from them apply directly to Coin Rush.
When you add sound, define the audio buses in the project, not in code. It's tempting to create "Music" and "SFX" buses from a script at startup. On desktop that works. In the web export, Godot wired our master bus back into those buses, making a loop that the browser silenced completely: no errors, just no sound. Create the buses in the Audio panel at the bottom of the editor instead, which saves them in default_bus_layout.tres. We hit this twice, in two different games, before it stuck.
You might not need sprite files at all. Tank Arcade has no image assets. The tanks, walls, crates, scorch marks and tread tracks are all drawn in code with Godot's _draw() functions, plus a glow layer for anything bright. For a game made of simple shapes, that's faster than finding art that matches, and the download stays tiny. Try replacing the coin's icon.svg with a _draw() that calls draw_circle() and see how far it takes you.
A best score needs somewhere to live. The "best score" idea in step 5 saves to a file. In a web build, that file lives in the browser's storage, and some places that host games, including the sandboxed play frame on our own arcade pages, don't allow any storage. Our games check with OS.is_userfs_persistent() before they save, and offer a separate full-screen page where saving works. Expect your save code to fail sometimes, and make sure the game still runs when it does.
What you just learned
You used scenes and nodes, a script per scene, the input system, physics bodies and areas, a signal, a timer driven by delta, and an export. Every bigger Godot game is these same pieces arranged in more ways. Ready for a third axis? Make your first 3D game in Godot uses the same pieces to build a small platformer. Or write a one-page design document for your own idea, and keep the scope small enough to finish.
Sources & credits
This guide is original writing by Santoshi Games. It draws on, and links to, the free resources below. All rights to them belong to their creators. Please support them.
- Godot Engine download, Godot Engine contributors
- Your first 2D game (Godot docs), Godot Engine contributors
- GDScript reference, Godot Engine contributors
- Exporting for the Web, Godot Engine contributors