Math & Vector2/Vector3
Master vector math, transforms, and geometric operations for movement, physics, and game calculations.
Scripting
No shortcutIntermediate7 min readQuick Reference
Math & Vector2/Vector3
Godot EngineKeyboard Shortcut
N/A
Where to Find
Select any node → Click Attach Script button, or Script Editor panel
Best Used For
- ▸Write game logic with variables and functions
- ▸Connect nodes via signals for decoupled systems
- ▸Expose Inspector properties for designer tweaking
Intermediate⏱ 30–60 minutes to master
Key Settings
Direction:Distance:Dot:Lerp:
Vector math is essential for game development. Godot provides Vector2 (for 2D) and Vector3 (for 3D) classes with built-in operations like normalization, dot product, and distance calculation.
Where to Find It
Vector classes are built into GDScript. Use them in any script for position, velocity, and direction calculations.
How to Use
- Direction:
var dir: Vector2 = Vector2(1, 0).normalized(). - Distance:
var dist = position.distance_to(target). - Dot:
var dot = dir1.dot(dir2)for angle between vectors. - Lerp:
position = position.lerp(target, 0.1)for smooth movement. - Rotation: Use
Vector2.RIGHT.rotated(rotation)for facing direction.
Pro Tips
- Always normalize direction vectors after getting them.
- Use
move_toward()for frame-rate-independent movement. - The dot product tells you if a target is in front (positive) or behind (negative).