Skip to main content

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:

TypeWhat you use it for
Vector2Positions, directions, velocities
ColorColors (tint, UI)
TimeTimestamps
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​

Quiz

Vector2

1 / 3

What 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​

UseApproach
Math / vectors / colorsReal Godot (Vector2, Color)
Simple actors / combat / scoregame_kit Player / Enemy / Game
Character / rigid / area bodiesgame_kit body mocks (next lessons)
Full scenes, Input, real physicsGodot 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