Skip to main content
Game Physics – Complete Beginner to Advanced Guide
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).
A point in space (e.g., 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. 1. Acceleration: How fast your speed is changing. (e.g., pressing the gas pedal adds 5m/s to your speed every second).
  1. 2. Velocity: Your current speed and direction. (e.g., traveling 60 mph North).
  1. 3. Position: Your actual location.
csharp
123456789
// The Core Math Loop of Physics Engines
void UpdatePhysics()
{
    // 1. Acceleration modifies Velocity
    velocity += acceleration * Time.deltaTime;

    // 2. Velocity modifies Position
    position += velocity * Time.deltaTime;
}

7. Visual Learning: Vector Addition

txt
123456
     (Wind Vector: 1,0)
       ----->
      |      \
      |       \  (Resulting Vector: 1,1)
      v        v
(Walk Vector: 0,-1)

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) or Vector3.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 of dir is 50. If you then say enemy.position += dir * speed, the enemy will warp 50 meters instantly! Always use dir.normalized to ensure the direction vector has a length of exactly 1 before applying speed.

10. Mini Project: Calculate and Move

Objective: Calculate the distance to a target and move toward it using Vector math.
csharp
123456789101112131415161718192021222324
class ChaserEnemy
{
    public Transform target;
    public float speed = 5.0f;

    void Update()
    {
        // 1. Calculate the exact distance
        float distance = Vector3.Distance(transform.position, target.position);
        Console.WriteLine("Distance to target: " + distance);

        if (distance > 1.0f)
        {
            // 2. Calculate the Direction Vector (Target - Me)
            Vector3 direction = target.position - transform.position;

            // 3. Normalize the vector (force length to 1)
            direction = direction.normalized;

            // 4. Move! (Direction * Speed * Time)
            transform.position += direction * speed * Time.deltaTime;
        }
    }
}

11. Practice Exercises

  1. 1. What is the standard mathematical formula used in code to find a Vector pointing directly from Object A to Object B?
  1. 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 DeltaTime factor 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?

14. FAQs

Q: Do I need to know Trigonometry (Sine, Cosine)? A: For basic physics, no. Vectors handle 95% of gameplay math. However, if you want to make an object orbit around a planet, or calculate the exact angle of a ricocheting bullet, basic Sine and Cosine knowledge becomes highly valuable.

15. Summary

In Chapter 2, we learned the language of game space. We explored how 3D coordinates locate objects, and how Vectors represent both the magnitude and direction of movement. We established the critical mathematical pipeline of physics: Acceleration modifies Velocity, and Velocity modifies Position over time. We also learned the vital importance of Vector Normalization to prevent catastrophic speed bugs when creating directional arrows.

16. Next Chapter Recommendation

We know the math behind movement. Now, we need to apply it to a character. Proceed to Chapter 3: Movement and Motion Systems.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·