CHAPTER 02
Intermediate
Mathematics for Game Physics
Updated: May 16, 2026
20 min read
# CHAPTER 2
Mathematics for Game Physics
1. Introduction
Physics is simply applied mathematics. To simulate a sword swinging, a bullet flying, or a car accelerating, you must understand the language the computer uses to describe space and movement. In game development, that language is entirely built upon Vectors. You do not need a Ph.D. in calculus, but you *do* need a rock-solid understanding of 3D coordinates, magnitude, and direction. In this chapter, we will master the mathematical foundations of game physics. We will explore Vectors, calculate the distance between objects, and define the core relationship between Position, Velocity, and Acceleration.2. Learning Objectives
By the end of this chapter, you will be able to:- Understand 2D and 3D Coordinate Systems (X, Y, Z).
- Define a Vector and differentiate between its Magnitude and Direction.
- Calculate the distance between two points in space.
- Understand the hierarchical relationship between Position, Velocity, and Acceleration.
- Use Vector Normalization to create pure directional arrows.
3. Coordinates and Space
Before an object can move, it must exist somewhere.- 2D Games: Use an X/Y grid. X is left/right. Y is up/down.
- 3D Games: Add a Z-axis. Z represents depth (forward/backward).
5, 10, 0) tells the engine exactly where to draw the object relative to the center of the world (0, 0, 0).
4. What is a Vector?
A Vector is a mathematical structure that holds numbers. In game engines, it is almost always used to represent two things simultaneously: Direction and Magnitude (Length/Speed).- Imagine a physical arrow pointing in 3D space.
- Which way is it pointing? (Direction).
- How long is the arrow? (Magnitude).
5. Vector Math Basics
-
Adding Vectors: If you are walking Forward
(0,0,1)and the wind is blowing you to the Right(1,0,0), your resulting movement vector is diagonal:(1,0,1).
- Finding Direction (Target - Source): To find the arrow pointing from an Enemy to the Player, you subtract the Enemy's position from the Player's position.
Vector3 direction = player.position - enemy.position;
-
Normalization: If you only care about the *direction* and want to strip away the length, you "Normalize" the vector. This forces the arrow's length to be exactly
1.0.
6. Position, Velocity, and Acceleration
These three concepts are the holy trinity of physics math. They cascade into each other over time (DeltaTime).- 1. Acceleration: How fast your speed is changing. (e.g., pressing the gas pedal adds 5m/s to your speed every second).
- 2. Velocity: Your current speed and direction. (e.g., traveling 60 mph North).
- 3. Position: Your actual location.
csharp
7. Visual Learning: Vector Addition
txt
8. Best Practices
-
Use Built-in Engine Math: Do not write your own Pythagorean theorem code to calculate distance. Every engine has highly optimized C++ math libraries. Use
Vector3.Distance(a, b)orVector3.Magnitude(v). Let the engine do the heavy lifting!
9. Common Mistakes
-
Forgetting to Normalize Directions: If you calculate
Vector3 dir = player.pos - enemy.pos;and the player is 50 meters away, the length ofdiris 50. If you then sayenemy.position += dir * speed, the enemy will warp 50 meters instantly! Always usedir.normalizedto ensure the direction vector has a length of exactly1before applying speed.
10. Mini Project: Calculate and Move
Objective: Calculate the distance to a target and move toward it using Vector math.
csharp
11. Practice Exercises
- 1. What is the standard mathematical formula used in code to find a Vector pointing directly from Object A to Object B?
- 2. If you have a Vector representing a character's velocity, what does "Normalizing" that Vector achieve?
12. MCQs with Answers
Question 1
In the physics hierarchy of movement, which property directly modifies Velocity over time?
Question 2
You subtract an Enemy's position from a Player's position to get a directional Vector. The Player is 100 units away. Before multiplying this Vector by the Enemy's walk speed, what MUST you do to prevent the Enemy from instantly teleporting 100 units?
13. Interview Questions
-
Q: Explain the mathematical relationship between Position, Velocity, and Acceleration. How does
DeltaTimefactor into this relationship within a Game Loop?
- Q: Describe the concept of Vector Normalization. Provide a concrete gameplay programming example where failing to normalize a vector results in a critical movement bug.
- Q: If you have an object's current Velocity vector, how do you use the Pythagorean theorem (or engine magnitude functions) to determine the object's exact speed in meters per second?