Mr Laliberte

Reach the Target: A Mini Project Guide

Game Development with Godot · Variables and Data · Lesson 4

Courses › Game Development with Godot › Reach the Target: A Mini Project Guide

What We’re Building

A player object that starts at a position you choose, and drifts toward a target object on its own once you press Playing has no keyboard or mouse needed. Along the way, it’ll also print a starting message.

Step 1: Add Two Objects

In your scene, add two objects:

  • A player object - this one will move

  • A target object - this one stays still

Give each one a Sprite2D or ColorRect so you can actually see it on screen. Attach a script to your player object — that’s the one that needs instructions.

Step 2: Set the Player’s Starting Position

Use the position values we used before:

func _ready():
    position.x = 100   # use your own number
    position.y = 300   # use your own number

Step 3: Add a Score Variable

Inside the same _ready() function, add a variable and a print statement:

func _ready():
    position.x = 100
    position.y = 300
    var score = 0
    print("Game started!")

Step 4: Make the Player Move Toward the Target

Use _process(delta) with the direction and speed:

func _process(delta):
    position.x += 150 * delta   # use your own speed number

If your target is to the left of your player instead of the right, use -= instead of += so your player moves the correct direction.

Step 5: Test It!

Press Play. Your player should appear at its starting position and drift toward the target. Check the Output panel, you should see “Game started!” appear once, right when the scene begins.

Stretch Goals (Optional)

If you finish early, try one or more of these:

  • Add a second object that moves in the opposite direction

  • Change the color or sprite of your player or target

  • Add a second variable (like lives or time) and print it too

  • Challenge: make the player slow down or stop when it reaches the target

Quick Reference Card

SymbolMeaning
var score = 0Creates a variable to store a starting value
position.x / position.yPlaces your objects on screen
position.x += speed * deltaMoves the player a little every frame
print("...")Shows a message in the Output panel

Welcome back