Every moving object in a game is a position, a direction, and a rule for changing them. Vectors describe positions and directions, trigonometry converts between angles and directions, physics updates motion each frame, rotations orient objects in 3D, and collision tests decide when objects touch.
A useful approach: Draw the situation → name the vectors → choose the formula → substitute numbers → check units and sign → test against the game (does it look right?).
1. Vectors
A vector stores a magnitude and a direction as components. In a game it can be a position, a velocity, or a direction.
Core Vector Operations
Operation
Formula
Game Use
Addition
Combine movement and wind
Scaling
Change speed
Magnitude
Speed or distance
Normalize
Direction only, length 1
Move
Update position each frame
Example: Normalize .
Step 1: Find the magnitude.
Step 2: Divide each component by 5.
Step 3: Check: .
Conclusion: The unit direction is .
Example: A player is at with velocity units/s. Find the position after s.
Step 1: Scale the velocity.
Step 2: Add to the position.
Conclusion: The new position is .
Always normalize a direction before multiplying by speed. Otherwise diagonal movement is faster than straight movement: has length .
Practice: Find the magnitude of .
Practice: Normalize .
, so .
2. Dot Product and Cross Product
These two products measure how vectors relate: the dot product returns a number about alignment, and the cross product returns a vector perpendicular to both inputs.
Result
Dot Product Meaning
Game Use
Vectors point roughly the same way
Target is in front
Vectors are perpendicular
Right-angle check
Vectors point roughly opposite
Target is behind
Example: Find the angle between and .
Step 1: Dot product: .
Step 2: Magnitudes: and .
Step 3: Solve for the angle.
Conclusion: The angle is .
Example: Find the surface normal of a triangle with edge vectors and .
Step 1: First component: .
Step 2: Second component: .
Step 3: Third component: .
Conclusion: . Normalize it to use it as a lighting or collision normal.
Example: Project onto the x-axis direction .
Step 1: Use .
Step 2: Substitute: .
Conclusion: The projection is . Projection is how you slide along walls and ramps.
Practice: Compute for and .
Practice: Compute .
3. Trigonometry
Trigonometry connects an angle to a direction. For a right triangle with hypotenuse :
Rearranged, a direction from an angle is , and radians relate to degrees by .
Angle
Radians
Sine
Cosine
Example: A projectile launches at speed m/s and angle . Find its velocity components.
Step 1: Horizontal: .
Step 2: Vertical: .
Conclusion: m/s.
Example: An enemy is at offset from the player. Find the facing angle.
Step 1: Use the two-argument arctangent, which respects the quadrant: .
Step 2: The point is in quadrant II, so .
Conclusion: The enemy is at . Plain would point the wrong way.
Most game engines use radians in their trig functions. Convert degrees before calling or .
Practice: Convert to radians.
Practice: Find the direction vector for a heading of with speed .
4. Physics for Movement
Physics in games is a loop: compute forces, update velocity, update position. Constant acceleration (such as gravity m/s²) follows these kinematic equations:
Quantity
Formula
Meaning
Velocity
Speed after time
Position
Position after time
Speed–distance
No time needed
Range
Flat-ground projectile
Force
Acceleration from force
Example: A character jumps upward at m/s with m/s². Find the time to the peak and the jump height.
Step 1: At the peak , so and s.
Step 2: Use with :
Conclusion: The peak occurs at s at a height of about m.
Example: Use semi-implicit Euler for a ball at , , , .
Step 1: Update velocity first: .
Step 2: Then update position with the new velocity: .
Conclusion: After one frame, and . Repeat every frame.
Example: Find the range of a projectile with m/s at .
Step 1: .
Step 2: .
Conclusion: The range is about m.
Practice: How fast is a dropped object moving after s of free fall ()?
m/s downward.
Practice: A kg object receives a force of N. Find its acceleration.
m/s².
5. Rotations in 2D and 3D
Rotating a point is multiplying it by a rotation matrix. In 2D, a counter-clockwise rotation by is:
In 3D, there is one matrix for each axis. The rotation about the x-axis is:
Example: Rotate by in 2D.
Step 1: and .
Step 2: .
Step 3: .
Conclusion: The result is .
Example: Rotate by about the x-axis.
Step 1: .
Step 2: .
Step 3: .
Conclusion: The result is : up turns into forward.
Quaternions
Chaining Euler-angle rotations can cause gimbal lock, where two axes align and a degree of freedom is lost. Engines use quaternions to avoid this. A rotation of about a unit axis is:
Example: Build the quaternion for about the z-axis.
Step 1: Half angle: .
Step 2: and .
Conclusion: .
Practice: Rotate by .
, , so the result is .
Practice: Why is used in a quaternion?
A quaternion rotates by sandwiching a vector, , which applies the rotation twice in effect, so each side carries half the angle.
6. Collision Detection
Collision tests are chosen to be cheap. Compare squared distances to avoid square roots.
Test
Condition
Notes
Circle / Sphere
Very fast
AABB (box)
and on every axis
Check x, y (and z)
Ray / Plane
Hit if
Reflection
Bounce off a surface
Example: Do circles at with and with collide?
Step 1: Squared distance: .
Step 2: Squared radius sum: .
Step 3: Compare: .
Conclusion: The circles are exactly touching, which counts as a collision.
Example: A ball with velocity hits a floor with normal . Find the bounce velocity.
Step 1: .
Step 2: .
Conclusion: : the vertical part flips and the horizontal part is kept.
Example: A ray starts at heading . The floor plane passes through with . Where does it hit?
Step 1: .
Step 2: , so .
Step 3: Hit point: .
Conclusion: The ray hits the floor at after .
Practice: Do boxes A: , and B: , overlap?
No. The x-ranges overlap, but the y-ranges and do not, so there is no collision.
Practice: Do spheres at , and , collide?
Squared distance is . Squared radius sum is . Since , they do not collide.
Key Takeaways
Vectors store positions, velocities, and directions; normalize directions before scaling by speed.
The dot product measures alignment and angles; the cross product gives perpendicular normals.
Trigonometry turns angles into directions; use atan2 to turn directions into angles.
Update velocity, then position, each frame using .
Rotation matrices rotate points; quaternions avoid gimbal lock in 3D.
Collision tests compare squared distances or ranges; reflection uses the surface normal.