Position, Velocity, Acceleration, Gravity and Trajectory for Game Physics
Have you ever wondered what Game Physics is? Is it that important? You probably heard of people commenting on some games and they are saying: “Wow! This game is a physics defying one!”
In the sense of making games, game physics is important. It deals with the computation of the motion of the objects in the game. This includes the playable characters, the NPC, the enemies, the environment objects and even the panorama or parallax. Game Physics also deals with the computation of the mechanical interactions of objects. This is usually seen in collisions (collision detection) in game programming. The computation however, may be realistic, approximate or intentionally distorted (via an effect).
Game physics supports immersion, new gameplay elements, prominent and used in high end games, most games that has good AI (Artificial Intelligence) movements, actions, graphics and behaviors is done by the game physics.
What physics formula are used in games? Let us discuss some of them:
Position and Velocity
Modeling the movement of objects with velocity
Where is an object at any time t?
Assume distance unit is in pixels
Position at time t for an object moving at velocity v, from starting position x0:
x(t) = x0 + vx t
y(t) = y0 + vy t
Constant acceleration: vx += ax, vy += ay
Use table lookup based on other factors:
Acceleration = acceleration_value(gear, speed, pedal_pressure)
Cheat a bit: acceleration = acceleration_value(gear, speed) * pedal_pressure
a = cos (v) * accelerationx
ay = sin (v) * acceleration
Piece-wise linear approximation to continuous functions
Gravity is a force between two objects:
Force F = G (m1m2)/ D2
G = 6.67 x 10-11 Nm2kg-2
mi: the mass of the two objects
D = distance between the two object
So both objects have same force applied to them
F=ma –> a=F/m
Assume mass of earth is so large it doesn’t move,
Assume D is constant because so far from center of earth
So get uniform acceleration
Position of falling object at time t:
x(t) = x0
y(t) = y0 + 1/2 * 9.8 m/s2 * t2
Incrementally, y += gravity (normalized to frame rate)
Study of the motion of objects without taking into account mass or force
- Basic quantities: position, time
- Basic equations:
d = vt
v = u + at
d = ut + at2/2
v2 = u2 + 2ad
where: t – (elapsed) time
d – distance (change in position)
v – (final) velocity (change in distance per unit time)
a – acceleration (change in velocity per unit time)
u – (initial) velocity
The laws of physics tell it exactly how the objects should move. Keep in mind that in the real world, so many factors influence motion that you can’t possibly take all of them into account. Some factors must be sacrificed to achieve real-time physics, but the ones that are sacrificed are usually quite insignificant.
Any time an object is moving, it has some speed.
Speed measures how fast an object is moving. If an object has speed, it also has a velocity, which is simply the vector version of speed. Velocity is speed with a direction. In one dimension, the direction is given by positive or negative.
Displacement with Constant Velocity
displacement = velocity * time (D = v * t) for any constant velocity v.
Displacement Between Frames
New_position = Old_position + Velocity * Time
where Time is one frame (usually 1/30th of a second).
A projectile is an object upon which the only force acting is gravity. There are a variety of examples of projectiles. An object dropped from rest is a projectile (provided that the influence of air resistance is negligible). An object that is thrown vertically upward is also a projectile (provided that the influence of air resistance is negligible). And an object which is thrown upward at an angle to the horizontal is also a projectile (provided that the influence of air resistance is negligible). A projectile is any object that once projected or dropped continues in motion by its own inertia and is influenced only by the downward force of gravity.
By definition, a projectile has a single force that acts upon it – the force of gravity. If there were any other force acting upon an object, then that object would not be a projectile. Thus, the free-body diagram of a projectile would show a single force acting downwards and labeled force of gravity (or simply Fgrav). Regardless of whether a projectile is moving downwards, upwards, upwards and rightwards, or downwards and leftwards, the free-body diagram of the projectile is still as depicted in the diagram at the right. By definition, a projectile is any object upon which the only force is gravity.
Now suppose that the gravity switch is turned on and that the cannonball is projected horizontally from the top of the same cliff. What effect will gravity have upon the motion of the cannonball? Will gravity affect the cannonball’s horizontal motion? Will the cannonball travel a greater (or shorter) horizontal distance due to the influence of gravity? The answer to both of these questions is “No!” Gravity will act downwards upon the cannonball to affect its vertical motion. Gravity causes a vertical acceleration. The ball will drop vertically below its otherwise straight-line, inertial path. Gravity is the downward force upon a projectile that influences its vertical motion and causes the parabolic trajectory that is characteristic of projectiles.
A projectile is an object upon which the only force is gravity. Gravity acts to influence the vertical motion of the projectile, thus causing a vertical acceleration. The horizontal motion of the projectile is the result of the tendency of any object in motion to remain in motion at constant velocity. Due to the absence of horizontal forces, a projectile remains in motion with a constant horizontal velocity. Horizontal forces are not required to keep a projectile moving horizontally. The only force acting upon a projectile is gravity!