Game Development Reference
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)
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
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: