Game Development Reference
In-Depth Information
If you look at the expressions in Equations (5.6) and (5.8), you will see that the location and
velocity in each coordinate direction is independent of the other directions. For example, there
are no x- or y-components in the z-direction equations of motion. Another important point to
note about the equations of motion under the gravity-only model is that there is nothing in the
equations about the mass or shape of the projectile. Under the gravity-only model, a 5 kg
cannonball and a 400 kg cow would have the same trajectory if they were launched from the
same spot with the same initial velocity.
Exercise
1.
A projectile starts its flight from the ground with an initial velocity of 20 m/s at an angle of 30 degrees in the
x-z plane. Using the gravity-only model, what is the projectile velocity when it hits the ground?
Finding the Time for a Projectile to Reach the Trajectory Apex
Because the equations of motion under the gravity-only model are simple algebraic expressions,
we can easily manipulate them to discover characteristics of the projectile trajectory. For example,
let's calculate the time it takes for a projectile to reach the apex, or highest point, of its trajectory.
When the projectile reaches its apex, its vertical velocity is equal to zero. The time at which this
event occurs can be found from Equation (5.6c).
v
== −
0
v
gt
(5.9)
z
z
0
v
t
=
z
0
(5.10)
g
Other interesting things can be computed from the gravity-only equations of motion such
as the time for the projectile to reach any altitude or the horizontal distance that the projectile
will travel.
Exercise
2.
A golf ball is shot into the air from the ground. If the initial horizontal velocity is 20 m/s and the initial vertical
velocity is 30 m/s , what is the horizontal distance the ball will travel before it hits the ground? Assume that the
golf course surface is flat and level.
The SimpleProjectile Class
Let's implement a projectile that travels under the gravity-only model in a class called
SimpleProjectile . The class will maintain the state of the projectile—its location and velocity
as a function of time. It will also implement code that will update the location and velocity of
the projectile.
Search WWH ::




Custom Search