Skip to content
GameDev Formulas
Math & physics for real games
Back to topics

All levels

Kinematics & Physics

Motion equations for velocity, acceleration, gravity, projectiles, and time-stepped simulation.

Formula

Velocity and Displacement

Updates position from velocity over time — the core of every movement system.

Intuition

Velocity is how fast position changes. Multiply by elapsed time to get how far you moved this frame.

Equation
p⃗t+Δt=p⃗t+v⃗ Δt\vec{p}_{t+\Delta t} = \vec{p}_t + \vec{v}\,\Delta t

Variables

p⃗t\vec{p}_t
Position at current time.
v⃗\vec{v}
Velocity vector (units per second).
Δt\Delta t
Time step / delta time in seconds.

Explanation

This is the simplest integration step. In real-time games, you apply it every frame using delta time so movement is frame-rate independent. Velocity can be constant or updated by acceleration/forces.

Where it shows up in games

Character movement, bullets, particles, camera motion, vehicles, and any object that moves over time.

Implementation

JavaScript & C++
JavaScriptjavascript
const player = { x: 0, y: 0 };
const velocity = { x: 120, y: 0 }; // pixels/sec

let last = performance.now();
function update(now) {
  const dt = (now - last) / 1000; // seconds
  last = now;

  player.x += velocity.x * dt;
  player.y += velocity.y * dt;

  requestAnimationFrame(update);
}
requestAnimationFrame(update);
C++cpp
struct Vec2 { float x, y; };

struct Body {
    Vec2 position;
    Vec2 velocity;
};

void integrate(Body& body, float dt) {
    body.position.x += body.velocity.x * dt;
    body.position.y += body.velocity.y * dt;
}

// In your game loop:
// float dt = getDeltaTimeSeconds();
// integrate(player, dt);

Formula

Constant Acceleration

Updates velocity and position under constant acceleration like gravity.

Intuition

Acceleration changes velocity every second. Gravity is the classic constant acceleration in games.

Equation
v⃗t+Δt=v⃗t+a⃗ Δtp⃗t+Δt=p⃗t+v⃗t Δt+12a⃗ Δt2\begin{aligned} \vec{v}_{t+\Delta t} &= \vec{v}_t + \vec{a}\,\Delta t \\ \vec{p}_{t+\Delta t} &= \vec{p}_t + \vec{v}_t\,\Delta t + \tfrac{1}{2}\vec{a}\,\Delta t^2 \end{aligned}

Variables

a⃗\vec{a}
Acceleration vector (units per second squared).
v⃗t\vec{v}_t
Velocity at current time.
p⃗t\vec{p}_t
Position at current time.

Explanation

When acceleration is constant, you can update velocity linearly and position quadratically. In many game loops, semi-implicit/Euler integration is used per frame; the exact formula is useful for analytic predictions like jump height or projectile landing time.

Where it shows up in games

Gravity, jumping, vehicle acceleration, knockback decay models, and projectile arcs.

Implementation

JavaScript & C++
JavaScriptjavascript
const body = {
  pos: { x: 0, y: 100 },
  vel: { x: 40, y: 0 },
};
const gravity = { x: 0, y: -9.81 }; // m/s^2, y-up

function step(dt) {
  body.vel.x += gravity.x * dt;
  body.vel.y += gravity.y * dt;
  body.pos.x += body.vel.x * dt;
  body.pos.y += body.vel.y * dt;

  // Simple ground collision
  if (body.pos.y < 0) {
    body.pos.y = 0;
    body.vel.y = 0;
  }
}
C++cpp
struct Vec2 { float x, y; };
struct Body { Vec2 pos; Vec2 vel; };

void step(Body& b, Vec2 accel, float dt) {
    b.vel.x += accel.x * dt;
    b.vel.y += accel.y * dt;
    b.pos.x += b.vel.x * dt;
    b.pos.y += b.vel.y * dt;

    if (b.pos.y < 0.0f) { // ground
        b.pos.y = 0.0f;
        b.vel.y = 0.0f;
    }
}

Formula

Projectile Motion

Models the arc of an object launched with initial velocity under gravity.

Intuition

Horizontal motion stays constant (ignoring drag), while vertical motion is affected by gravity, creating a parabola.

Equation
x(t)=x0+v0cos⁡(θ) ty(t)=y0+v0sin⁡(θ) t−12gt2\begin{aligned} x(t) &= x_0 + v_0\cos(\theta)\,t \\ y(t) &= y_0 + v_0\sin(\theta)\,t - \tfrac{1}{2}g t^2 \end{aligned}

Variables

v0v_0
Initial launch speed.
θ\theta
Launch angle from horizontal.
g\text{g}
Gravity magnitude.
t\text{t}
Time since launch.

Explanation

Projectile motion decomposes into independent axes. This gives you predictable arcs for grenades, arrows, cannonballs, and jump previews. In real games, you may add drag, wind, or collision, but the analytic form is a great baseline.

Where it shows up in games

Arcing projectiles, trajectory previews, aiming assists, ballistic AI, and jump arc visualization.

Implementation

JavaScript & C++
JavaScriptjavascript
function projectilePosition({ x0, y0, speed, angleRad, g, t }) {
  return {
    x: x0 + speed * Math.cos(angleRad) * t,
    y: y0 + speed * Math.sin(angleRad) * t - 0.5 * g * t * t,
  };
}

// Sample trajectory points for a line renderer
function sampleTrajectory(params, steps = 30, dt = 0.1) {
  const points = [];
  for (let i = 0; i <= steps; i++) {
    points.push(projectilePosition({ ...params, t: i * dt }));
  }
  return points;
}
C++cpp
#include <cmath>
#include <vector>

struct Vec2 { float x, y; };

Vec2 projectilePosition(float x0, float y0, float speed, float angleRad, float g, float t) {
    return {
        x0 + speed * std::cos(angleRad) * t,
        y0 + speed * std::sin(angleRad) * t - 0.5f * g * t * t
    };
}

std::vector<Vec2> sampleTrajectory(float x0, float y0, float speed, float angleRad, float g) {
    std::vector<Vec2> points;
    for (int i = 0; i <= 30; ++i) {
        float t = i * 0.1f;
        points.push_back(projectilePosition(x0, y0, speed, angleRad, g, t));
    }
    return points;
}