Using forces, velocities, and torque
No matter what kind of simulation we are creating, we will more than likely want to control at least one body. To move bodies in Box2D, we can apply linear or angular forces, set linear or angular velocities, and apply an angular force in the form of torque. In this recipe, we will see how we can apply these forces and velocities on multiple bodies.
Getting ready...
Follow the steps in the Introduction to the Box2D physics extension section at the beginning of the chapter to create a new activity that will facilitate the creation of bodies that will react to forces, velocities, and torque. Then, update the activity to include the additional code from the ForcesVelocitiesTorqueActivity
class found in the code bundle.
How to do it...
Refer to the supplemental ForcesVelocitiesTorqueActivity
class for the complete example of this recipe. We will cover only the basics of the recipe in this section:
We will first work with the methods that handle the linear motion...