Home โ€บ Module 1
๐Ÿ”ฅ Module 01 ยท Advanced

3D Game Math

Ever wonder how your character in a game knows which way to run or how high to jump? It's all powered by secret invisible arrows! ๐Ÿน Today, we're learning the magic math that brings 3D worlds to life, and even helps AI build entire levels from just a few words! Ready to peek behind the curtain?

A vector is like an instruction: "Go this way, this fast!"

๐Ÿงญ

Vectors in 3D Space: The Secret Laboratory ๐Ÿงช

Okay, let's break it down. Imagine you're drawing in a video game world. A vector is just two things:

That's it! Game engines use these invisible arrows to figure out everything from where to aim a rocket to how fast a car is driving.

๐Ÿ’ก Pan's Pro Tip: The GPS of Games!

Think of a Vector like a set of GPS instructions. Instead of saying "Go to the store," a vector says "Walk 5 steps North, and 2 steps East." When you multiply that vector (called scaling), it's like telling your player to sprint instead of walk!

โ–ถ IN A REAL ENGINE (UNITY/C#)

// Creates a vector to move the player forward on the Z-axis
Vector3 moveDirection = new Vector3(0, 0, 1.0f); // <-- This is the vector! (X, Y, Z)

// Applies speed to that direction
float speed = 5.0f;
player.transform.position += moveDirection * speed * Time.deltaTime;

Notice the `(X, Y, Z)` values? That's a vector in action! We use `Time.deltaTime` to make the movement smooth, no matter how fast or slow the computer is. It's a pro move for frame-rate independence.

๐Ÿค” But Why Use Vectors?

Great question! Game engines do math thousands of times per second. Vectors are a super-efficient way to answer questions like:

Learning vectors is like learning the secret language all game characters use to talk to each other!

๐Ÿ“บ Brackeys โ€” "Introduction to Vectors in Unity!" โ€” See how a real game engine uses vectors to handle movement. A perfect, quick introduction to a huge topic!

โšก Logic Check

Your player has a special "sprint" ability. When they sprint, their movement vector's length doubles from 5.0 to 10.0. To make sure they always sprint in the right direction, what math operation should you use on the direction vector *before* you multiply it by the sprint speed?

Scale the vector by 2.
Normalize the vector.
Use the Dot Product.

๐Ÿ’ก Dot Product: The Friendship Test!

What about that "Dot Product" thing? Think of it as asking two vectors: "How much are you pointing in the same direction?" It gives you a single number with a secret meaning:

  • Result > 0: The enemy is generally in front of you. โœ…
  • Result = 0: The enemy is exactly to your side (90 degrees). โžก๏ธ
  • Result < 0: The enemy is behind you! โš ๏ธ

Games use this to see if an enemy is in a player's field of view! We'll use this later to build a smart AI. ๐Ÿ‘€

๐Ÿ’ป Sandbox: Game Physics Simulator

๐Ÿ›ก๏ธ Safety Check: When you talk to an AI, remember the secret agent rule: never share your full name, school, or address. And remember, the AI is a fun, creative partner for coding, but it's not always a truthful one. Don't ask it for personal facts!

Time to write some real physics logic. A character's final movement in one frame is the sum of all forces acting on them. In the box below, do two things:
1. Create a `gravity` vector that pulls the player down on the Y-axis with a force of `9.8`.
2. Create a `jumpForce` vector that pushes the player up on the Y-axis with a force of `20.0`.
3. Add them together and apply the result to the `player.velocity`. Can you write the C# code?

Awaiting physics simulation...

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง Parent Corner

Wondering what "vectors" are? Think of them as the basic instructions for movement and direction. When your child understands vectors, they're learning the fundamental language of not just games, but also animation, robotics, and even the GPS in your car!

Conversation Starter: Ask your child, "If you were a game character right now, what real-world object would your 'forward' vector be pointing at?"

Screen-Free Fun: Try a "Family Game Jam" this weekend! The mission: design a simple board game on paper together. It's a fantastic way to teach the core loops of game design (rules, goals, fun) without a screen.

๐Ÿš€ Launch Pad: Your Next Steps

โ† Previous