About the Author
Anthony KOZAK is a senior game developer and technical director with over 16 years of professional experience in the video game and interactive media industry. Having shipped titles at world-class studios including Ubisoft, Anthony has worked across a wide spectrum of platforms — from PC and console to mobile and VR — accumulating deep expertise in real-time 3D programming, engine architecture, and the mathematical foundations that underpin every game ever made.
Beyond his studio career, Anthony is the founder of Indietrainers, an online platform dedicated to training the next generation of Unity3D developers. Through Indietrainers he has taught thousands of students the art and craft of game development, with a philosophy that good code starts with a clear mental model — and a clear mental model starts with understanding the math. This book grew directly out of that teaching philosophy: it is the resource Anthony wished he had had when he first encountered Unity3D's coordinate system, its vectors, and its quaternion-based rotations.
When he is not writing code or lesson plans, Anthony speaks at developer conferences, contributes to open-source Unity tooling, and mentors indie studios navigating the transition from prototype to shipped product. You can follow his work and download the source files that accompany this book at indietrainers.com.
Introduction
Mathematics is the invisible engine of every game. When a character sprints across a battlefield, vectors determine the direction and magnitude of the motion. When a camera smoothly follows a player, linear interpolation — Lerp — orchestrates every frame. When a bullet traces an arc through the air, parabolic trajectory equations govern its path. Understanding the mathematics behind Unity3D does not just make you a better programmer; it makes you a better game designer, because you begin to see why things feel the way they do.
This book is a practical guide to the mathematics you will actually use day-to-day as a Unity3D developer. It is not a pure mathematics textbook, and it makes no attempt to cover every theorem or proof. Instead, each concept is introduced in the context of a concrete Unity problem, illustrated with working C# code, and reinforced with exercises you can run directly in the Unity editor. The goal is to build intuition alongside technique — so that when you encounter a new problem in your own projects, you will recognise the mathematical pattern underneath it and know exactly which tool to reach for.
The topics covered in this book are:
- The Basics — local and global space, the Transform component, Cartesian coordinates, calculating distances, clamping values, working with percentages, and linear interpolation.
- Vectors A to Z — what vectors are, how to move objects with them, the Dot and Cross products, normalization, MoveTowards, space conversion, and debugging vectors visually in the Scene view.
- Quaternions and Rotations — understanding Unity's Quaternion type, Euler angles, LookRotation, Slerp, and practical rotation techniques that avoid gimbal lock.
- Physics and Forces — working with Rigidbody, AddForce, torque, drag, and the difference between physics-driven and transform-driven motion.
- Raycasting — Physics.Raycast, layer masks, RaycastHit, SphereCast, and practical patterns for click detection, line-of-sight, and ground snapping.
- Trigonometry — sine, cosine, tangent, and their inverses; circular motion; oscillation; and how to use Mathf's trig functions to create organic, wave-based animations.
- Easing and Tweening — ease-in, ease-out, ease-in-out, and custom animation curves; building a lightweight tweening system in pure C#.
- Trajectories — ballistic trajectories, predicting landing positions, and computing the launch angle needed to hit a target at a given distance and height.
- Transformation Matrices — how Unity uses 4×4 matrices internally, the TRS matrix, and how to compose transforms manually when the built-in API falls short.
Each chapter builds on the previous ones, but the book is also designed to work as a reference. If you need to revisit vectors without rereading the basics chapter, you can do so — every section is self-contained enough to stand alone.
Prerequisites
This book assumes that you have a working installation of Unity3D (any version from Unity 5 onwards is compatible with the concepts and code presented here; the examples were written and tested against Unity 2018). You should be comfortable creating a new Unity project, adding GameObjects to a scene, and attaching a MonoBehaviour script to an object. You do not need to be an expert C# programmer, but you should understand the fundamentals: classes, methods, variables, conditionals, and loops.
If you have never written a line of C# before, we recommend spending a few hours with Unity's own
beginner scripting tutorials before starting here. Once you can write a MonoBehaviour with a
Start() and Update() method, you are ready to begin.
No prior knowledge of mathematics beyond high-school algebra is required. Concepts such as vectors, dot products, and matrices are introduced from scratch, always in the context of Unity, so even if you have never studied linear algebra formally you will be able to follow along.
Source Files
Every exercise and example in this book has an accompanying Unity project that you can download, open, and run directly. Seeing the code in action — and being able to modify it and observe the results in real time — is one of the most effective ways to build genuine understanding.
How to Download the Source Files
All source files are available for free at indietrainers.com. Navigate to the book's
dedicated page, log in (or create a free account), and click the download link for the chapter you are
currently reading. Each chapter's project is provided as a self-contained .zip archive.
How to Open a Unity Project
Once you have downloaded and unzipped a chapter's project folder, opening it in Unity is straightforward:
- Launch the Unity Hub.
- Click the Add button in the Projects tab.
- Navigate to the unzipped folder and select it. Unity Hub will detect it as a valid project.
- Click the project name to open it. Unity will import the assets and compile the scripts automatically. This may take a minute on the first open.
-
Once the editor loads, open the scene listed in the chapter instructions (usually found in
Assets/Scenes/) and press Play to see the example in action.
If Unity warns you about a version mismatch, you can safely choose Continue — the projects use only standard Unity APIs that are stable across versions.
Who Is This Book For?
This book is written for Unity3D developers who want to level up. You may be a self-taught developer who has been building games for a year or two and finds that you often have to look up the same mathematical tricks over and over. Or you may be a computer-science graduate who understands the theory but has never had to apply it in a real-time 3D engine. Or you may be a game designer who is starting to write scripts and wants to understand why the code you copy from Stack Overflow actually works.
Whatever your background, if you use Unity3D and you want to understand the mathematics that power it at a deep, intuitive level — this book is for you. By the time you reach the final chapter, you will not just know how to move an object along a parabolic arc or rotate it smoothly toward a target. You will know why those techniques work, and you will be able to invent new ones yourself.
Let's get started.
Need help with Unity3D development?
I'm a senior developer with 16+ years experience, including AAA projects at Ubisoft. Let's discuss how I can help with your game or interactive project.
Start a Conversation