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.
Variables
- Position at current time.
- Velocity vector (units per second).
- 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.
- Always multiply by delta time in frame-based updates for frame-rate independence.
- Clamp very large dt values after pauses/tab switches to avoid physics explosions.
- Using fixed pixel-per-frame movement makes gameplay speed depend on frame rate.
- Use seconds for dt in simulation math; convert units at boundaries if needed.
- Consider a fixed timestep for physics and variable timestep for rendering.
Implementation
JavaScript & C++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);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);