Build a submarine

In Chapter 7 we had a simple but interesting example of a ball floating in water. It is actually quite easy to modify that example and turn it into an interactive submarine of a type that can be used in simple 2D games. Let's first quickly review the main physics involved.

Brief review of the physics

In the floating ball example, we identified three main forces that acted on the ball: gravity, upthrust, and drag, which are given respectively by the following formulas:

Image

Note that we have written the upthrust formula in vector form: the minus sign is because upthrust acts upward, opposing the gravity vector g. Just as a reminder, ...

Get The Essential Guide to Physics for Flash Games, Animation, and Simulations now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.