Game Development Reference
In-Depth Information
Figure 9-27 illustrates a simple example of how these three values can describe an object bouncing
on a surface.
Direction (dot product)
New Direction (projection)
Tangent Velocity
Platform
Figure 9-27. Use some vector math to help with bounce and fricition.
These formulas will work no matter which side and from which direction the lh]uan is hitting the
lh]pbkni. Vector math is very helpful for these sorts of physics calculations in games. If you go on to
do much more game design outside the pages of this topic, consider studying a bit of vector math in
more detail.
Now that you have those values, you can multiply them with the ^kqj_a and bne_pekj values that
were supplied to the method as parameters. An important thing about the next bit of code is that it
applies the forces only if the lh]uan is moving into a collision with the platform. Without this check,
the player will appear to be fixed to the platform with glue when it lands on it:
++=llhu_khheoekjbkn_aoebpdak^fa_peoikrejcejpk]_khheoekj
eb\$`ena_pekjKb?khheoekj8,%
w
++?]h_qh]papdabne_pekj
bne_pekjT9p]jcajp[Rt&bne_pekj7
bne_pekjU9p]jcajp[Ru&bne_pekj7
++?]h_qh]papda]ikqjpkb^kqj_a
^kqj_aT9jas@ena_pekj[T&^kqj_a7
^kqj_aU9jas@ena_pekj[U&^kqj_a7
y
ahoa