Projectile Motion & Trajectory
Visualize parabolic trajectories for jumps, arrows, and grenades.
How does it work? ↓The Physics of a Parabola
In game development, simulating a projectile (like an arrow, a thrown grenade, or a character jumping) requires understanding two independent dimensions of motion:
- Horizontal Motion (X): Without air resistance, a projectile travels horizontally at a constant mathematical speed.
- Vertical Motion (Y): Gravity constantly accelerates the projectile downward, altering the length and angle of its velocity vector over time.
The Kinematic Equation
You can calculate the exact position of a projectile at any given time t using this formula:
Position.X = InitialVelocity.X * t
Position.Y = InitialVelocity.Y * t + (0.5 * Gravity * t * t)
Position.Y = InitialVelocity.Y * t + (0.5 * Gravity * t * t)
By simply plugging in different values of t (e.g., 0.1, 0.2, 0.3 seconds) sequentially in a loop, you can draw a perfectly accurate prediction arc before the user even throws the object!
Answers to Common Developer Questions
What is the formula for 2D Projectile Motion?
A projectile moving in 2D space splits its velocity into two independent axes. The X velocity remains entirely constant over time (`Velocity X * Time`), while the Y velocity continuously decreases due to gravity (`Velocity Y * Time - 0.5 * Gravity * Time^2`).
How do you calculate jump height in a 2D Platformer?
To calculate the apex (maximum height) of a jump arc, square the initial Vertical Velocity and dividing by twice the Gravity: `MaxHeight = (VelocityY * VelocityY) / (2 * Gravity)`. This allows you to guarantee level design platforms are exactly mathematically reachable.
How do I predict where an arrow or bullet will land?
By solving the projectile motion kinematic equations for 'Time' where Y equals 0 (the ground), you can project an exact parabola. Multiply that total air time by the constant X velocity to find the precise horizontal distance the object will travel.