Game Development Reference
In-Depth Information
Applying Forces to Bodies
Box2D world is ruled by forces and is able to apply them to bodies to give us
a realistic simulation, but if you couldn't manually apply forces to bodies, you
won't be able to move bodies, fire bullets, throw birds, drive cars, and do all the
awesome things you see when you play physics games.
In this chapter you will learn how to apply forces to move bodies in different
ways, managing a lot of new Box2D features including:
• Applying a force to a body
• Applying an impulse to a body
• Setting the linear velocity to a body
• Knowing the mass of a body
• Applying the right kind of force according to your gameplay needs
• Mixing physics with non-physics assets in your game
By the end of the chapter, you will be able to create an Angry Birds level,
sling included.
Falling apples, revamped
The legend says Newton discovered the gravity after being hit by a falling apple.
You will learn forces by raising some objects from the ground.
We'll start with a basic script that will place three dynamic spheres on a static floor.
The following will be your starting Main class:
package {
import flash.display.Sprite;
import flash.events.Event;
Search WWH ::




Custom Search