Godot / 6 MIN READ
Godot 2D setup 101
Godot 2D 101
From the original Fervor library. Examples may use older package versions.
Oh, you wanna dive into the glorious world of game development with Godot? Nice. Buckle up, ‘cause we’re about to set up a basic 2D game faster than you can say “this is totally not a Unity clone.”
🎮 How to Set Up a Basic 2D Game in Godot (for absolute legends)
Step 1: Install Godot (duh)
- Go to Godot Engine’s official website and download the latest stable version.
- It’s lightweight. Like, your fridge probably has more processing power than this thing needs.
Step 2: Create a New Project
- Open Godot. Hit that New Project button like it owes you money.
- Name it something cool, like “Epic 2D Adventure of Doom” or “Bob’s Mildly Interesting Quest.”
- Choose a folder, click Create & Edit, and boom, you’re in.
Step 3: Set Up Your First Scene
- Godot works with scenes (think of them as LEGO sets that you can piece together).
- Click 2D Scene (‘cause we ain’t making 3D… yet).
- Rename the default node to something fancy, like GameRoot or The Supreme Overlord of Nodes.
Step 4: Add a Player Character
- Add a new Node2D (this will be your player).
- Inside it, add a Sprite2D (this is the actual image of your character).
- Import a sprite (drag and drop an image into
res://, then assign it in the Sprite2D node). - Add a CollisionShape2D (so your character doesn’t just phase through walls like a glitchy ghost).
- Set a shape (Rectangle or Circle).
- Make sure it covers the sprite properly.
Step 5: Movement Script (Make It Move, Baby)
- Select the player node and hit Attach Script (that lil’ scroll icon).
- Use GDScript (Godot’s built-in scripting language).
- Copy-paste this magic into
player.gd:
extends CharacterBody2D
@export var speed = 200 # You can tweak this later
func _physics_process(delta):
var direction = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
direction.x += 1
if Input.is_action_pressed("ui_left"):
direction.x -= 1
if Input.is_action_pressed("ui_down"):
direction.y += 1
if Input.is_action_pressed("ui_up"):
direction.y -= 1
direction = direction.normalized()
velocity = direction * speed
move_and_slide()
- Boom! Your character now moves with arrow keys.
Step 6: Setting Up the Game World
- Create another Node2D (name it “Level”).
- Add a TileMap to it (for easy level design).
- Use TileSet Editor to create a simple map.
- Drag in some cool pixel art tiles (or just draw random squares like a chaotic genius).
Step 7: Add an Enemy (For Drama)
- Duplicate your Player Node, rename it Enemy, and tweak the script so it chases the player.
- Use this simple AI:
extends CharacterBody2D
@export var speed = 100
var player = null
func _ready():
player = get_node("/root/GameRoot/Player") # Adjust the path as needed
func _physics_process(delta):
if player:
var direction = (player.global_position - global_position).normalized()
velocity = direction * speed
move_and_slide()
- Now you’re being hunted. Fun!
Step 8: Add Some UI
- Add a Control node.
- Inside it, add a Label (to display something like “Score: 0”).
- Make it update in a script.
Step 9: Play & Debug
- Smash that Play button.
- Watch your beautiful, slightly janky game run.
- Cry tears of joy (or frustration when debugging starts).
🎉 Congratulations! You just made a basic 2D game in Godot!
Now go forth and add more chaos—power-ups, enemies, explosions, or even a banana that speaks in riddles.
Oh, you wanna go from indie dev to full-blown gaming overlord? I like your energy. Let’s level up this game so hard, your code starts glowing.
🆙 BONUS ROUND: How to Level Up Your Basic 2D Game in Godot
1️⃣ Smooth Player Animations (Because Static Sprites Are for Noobs)
Your character is just sliding around like a PowerPoint transition? Let’s fix that.
- Add an AnimatedSprite2D instead of the static Sprite2D.
- Import different animation frames (idle, walking, etc.).
- In the Animation Frames panel, set up animations like:
"idle"→ just standing there, menacingly."walk"→ moving like they mean business.
- Add this animation logic to
player.gd:
if direction == Vector2.ZERO:
$AnimatedSprite2D.play("idle")
else:
$AnimatedSprite2D.play("walk")
Boom. Now your character isn’t just levitating like a haunted PNG.
2️⃣ Attack System (Because Combat = Fun)
We need to let the player smack things. Here’s how:
🔹 Melee Attack (Simple & Satisfying)
- Add an Area2D as a child of the player.
- Inside it, add a CollisionShape2D (adjust size).
- Add this script:
extends Area2D
func _on_area_entered(area):
if area.is_in_group("enemies"):
area.queue_free() # Destroys enemy on hit
- Connect it to an attack button (like Spacebar) and show a sword swing animation.
3️⃣ Enemy AI That’s Smarter Than a Goldfish
Your enemy currently just runs at the player like a sleep-deprived intern?
Let’s add some pathfinding (so they don’t get stuck on walls like an idiot).
- Add a NavigationRegion2D to the level.
- Add a NavigationAgent2D to your enemy.
- Modify
enemy.gd:
extends CharacterBody2D
@export var speed = 80
@onready var nav_agent = $NavigationAgent2D
func _process(delta):
if player:
nav_agent.target_position = player.global_position
var next_point = nav_agent.get_next_path_position()
var direction = (next_point - global_position).normalized()
velocity = direction * speed
move_and_slide()
Now enemies find their way instead of running into walls like a confused toddler.
4️⃣ Parallax Background (Make It Look Juicy)
Right now, your game looks like a PowerPoint presentation from 2004. Let’s add some depth with a ParallaxBackground.
- Add a ParallaxBackground node to the scene.
- Add a ParallaxLayer inside it.
- Drop in a cool sky image (or something that screams “next-level gaming”).
- Make it scroll with this script:
extends ParallaxBackground
@export var speed = 30
func _process(delta):
scroll_offset.x -= speed * delta
Now your background moves and looks sexy.
5️⃣ Juice It Up (Game Feel = Chef’s Kiss)
- Screenshake:
func shake(amount):
position = Vector2(randf_range(-amount, amount), randf_range(-amount, amount))
- Particles for attacks & movement
- Camera zoom when attacking or hit
- Sound effects that slap harder than a bass drop
6️⃣ Level System & Progression
- Unlockable areas
- Level select screen
- Upgrades (e.g., faster speed, bigger attacks, cooler hats, etc.)
7️⃣ Add a Boss Battle (Because Why Not)
Your enemies are weak? Drop in a boss.
- Make them big, angry, and unpredictable.
- Give them multiple attack patterns (jump slams, lasers, chaotic nonsense).
- Add an epic theme song.
🔥 Conclusion
Now your game is officially leveled up. It has animation, combat, smart enemies, juicy effects, and an actual goal.
Basically, it went from “cute prototype” to “indie game that could destroy friendships.”
Now go forth, code warrior, and make something ridiculous. 🚀🎮