Chapter 5a - Vectors and the game kit
Real engine types in the sandboxβ
Even without the Godot editor, headless scripts still get real engine math:
| Type | What you use it for |
|---|---|
Vector2 | Positions, directions, velocities |
Color | Colors (tint, UI) |
Time | Timestamps |
var v = Vector2(3, 4)
print(v.length()) # 5
print(v.normalized()) # length 1, same direction
print(Vector2.RIGHT) # (1, 0)
print(Vector2.UP) # (0, -1) β Godot Y grows downward on screen
π§ͺ Try Vector2
Mini quiz β vectorsβ
Vector2
1 / 3What is Vector2(3, 4).length()?
Pick an answer to see if you are right.
The teaching kit (game_kit.gd)β
Full scenes, Input, and physics frames need the editor. For sandbox lessons, Piston injects res://game_kit.gd β small mocks shaped like game actors.
var Kit = preload("res://game_kit.gd")
var game = Kit.make_game()
var foe = game.spawn_enemy(Vector2(40, 0))
game.player.speed = 80
game.player.move(Vector2.RIGHT, 0.5)
print(game.player.position)
print(Kit.near(game.player.position, foe.position, 50))
π§ͺ Try the kit
Real vs mockβ
| Use | Approach |
|---|---|
| Math / vectors / colors | Real Godot (Vector2, Color) |
| Simple actors / combat / score | game_kit Player / Enemy / Game |
| Character / rigid / area bodies | game_kit body mocks (next lessons) |
| Full scenes, Input, real physics | Godot editor (not this sandbox) |
Player.move(direction, delta) does:
velocity = direction.normalized() * speed
position += velocity * delta
Challenge: survive one hitβ
Create a game, spawn an enemy, let it attack once, print the player's hp.
Starter HP is 100. Enemy damage is 5. Expected: 95.
Exercisesβ
Vectors first, then movement, then proximity.
Activity: Vector length
Create Vector2(6, 8) and print its length() as an int.
10