Game Dev Cheat Sheet

Game Maths Cheat Sheet

Interactive visualisations and Unity C# code for the most common game development maths. Drag the points, adjust the sliders, and copy the code.

Game development relies on a core set of maths concepts that come up repeatedly: measuring distances, calculating angles, interpolating between values, and working with vectors. This interactive cheat sheet lets you drag points, adjust parameters, and see the maths in action, with copy-paste Unity C# code for each concept.

1. Distance Between Two Points

Formula: √((x₂−x₁)² + (y₂−y₁)²)

Drag the dots to explore.

// 2D
float dist = Vector2.Distance(a, b);

// 3D
float dist = Vector3.Distance(a, b);

2. Angle Between Two Points

Formula: atan2(y₂−y₁, x₂−x₁)

Drag the target point to change the angle. Canvas Y is inverted, so the angle is measured from the positive X axis.

float dx = target.x - origin.x;
float dy = target.y - origin.y;
float angle = Mathf.Atan2(dy, dx) * Mathf.Rad2Deg;

3. Move Towards a Target

Formula: position + direction × speed × deltaTime

Drag the target. The mover chases it at a fixed speed.

transform.position = Vector3.MoveTowards(
    transform.position,
    target.position,
    speed * Time.deltaTime
);

4. Linear Interpolation (Lerp)

t:0.50

Formula: a + (b − a) × t

When t=0 the result is A, when t=1 the result is B. Values in between blend smoothly.

float val = Mathf.Lerp(a, b, t);
Vector3 pos = Vector3.Lerp(a, b, t);
Color col = Color.Lerp(a, b, t);

5. Dot Product

Formula: a.x×b.x + a.y×b.y (using normalised vectors)

Positive = same direction. Zero = perpendicular. Negative = opposite.

float dot = Vector3.Dot(a.normalized, b.normalized);
// 1 = same dir, 0 = perpendicular, -1 = opposite

6. Cross Product

Formula: (a.y×b.z − a.z×b.y, a.z×b.x − a.x×b.z, a.x×b.y − a.y×b.x)

Result is perpendicular to both input vectors. Magnitude equals the area of the parallelogram they form.

Vector3 cross = Vector3.Cross(a, b);

7. Normalise a Vector

Formula: v / |v|

A normalised vector keeps its direction but has a magnitude of 1. The dashed circle represents unit length.

Vector3 dir = vector.normalized;
// dir has magnitude 1

8. Reflect a Vector

Formula: d − 2(d·n)n

Drag the source of the incoming vector. The reflected vector mirrors across the surface normal.

Vector3 reflected = Vector3.Reflect(direction, normal);

9. Point in Circle

Formula: distance(point, centre) ≤ radius

Drag the point. It turns green when inside the circle, red when outside.

bool inside = Vector3.Distance(point, centre) <= radius;

10. Point in Rectangle (AABB)

Formula: point.x ≥ min.x && point.x ≤ max.x && point.y ≥ min.y && point.y ≤ max.y

Drag the point to test axis-aligned bounding box containment.

bool inside = bounds.Contains(point);

11. Sine Wave Motion

Amplitude:50
Frequency:2.0
Phase:0.00

Formula: amplitude × sin(frequency × time + phase)

Adjust the sliders to see how amplitude, frequency, and phase affect the wave.

float y = Mathf.Sin(frequency * Time.time + phase) * amplitude;
transform.position = new Vector3(
    transform.position.x,
    y,
    transform.position.z
);

12. Random Point in Circle

0 points

Formula: centre + Random.insideUnitCircle × radius

Uses uniform distribution (sqrt of random radius) so points do not cluster at the centre.

Vector2 point = (Vector2)transform.position
    + Random.insideUnitCircle * radius;

13. SmoothDamp (Camera Follow)

Smooth Time:0.30
Max Speed:50

Critically damped spring: smoothly follows a moving target without overshooting.

Drag the green target. The blue follower chases it using SmoothDamp. The pink arrow shows current velocity. Lower smooth time means faster response; max speed caps the velocity.

private Vector3 velocity = Vector3.zero;

void LateUpdate()
{
    Vector3 target = targetTransform.position;
    transform.position = Vector3.SmoothDamp(
        transform.position,
        target,
        ref velocity,
        smoothTime,    // 0.30f
        maxSpeed       // 50f
    );
}

14. Remap (InverseLerp + Lerp)

Formula: Lerp(outMin, outMax, InverseLerp(inMin, inMax, value))

Drag the blue point on the input line. The green point on the output line shows the remapped value. Edit the range inputs to change both scales.

// Remap a value from one range to another
float t = Mathf.InverseLerp(inMin, inMax, value);
float result = Mathf.Lerp(outMin, outMax, t);

// Common example: map health (0-100) to bar fill (0-1)
float fill = Mathf.InverseLerp(0f, maxHealth, currentHealth);
healthBar.fillAmount = fill;

// Remap utility function
public static float Remap(float value,
    float inMin, float inMax, float outMin, float outMax)
{
    float t = Mathf.InverseLerp(inMin, inMax, value);
    return Mathf.Lerp(outMin, outMax, t);
}