Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

# Understanding Box2D applicable forces

In Box2d, bodies aren’t only affected by gravity and collisions, but you can also apply forces to them.

Knowing the right force to apply is very important when you want to control a body, as you may want to do in a Flash game

Let’s see the forces you can apply:

Applying a force

`public function ApplyForce(force:b2Vec2, point:b2Vec2):void`

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body, so you don’t have to wake it up by yourself.

The force is applied inNewtons (N).

Applying an impulse

`public function ApplyImpulse(impulse:b2Vec2, point:b2Vec2):void`

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body, so you don’t have to wake it up by yourself.

The impulse is applied in Newton-seconds or kg-m/s.

Setting a linear velocity

`public function SetLinearVelocity(v:b2Vec2):void`

Set the linear velocity of the center of mass. This function will not work if the body is sleeping, so you must wake it up with `SetAwake` before applying the velocity.

What force should I apply?

You should choose the force according to the result you want to achieve. Let’s suppose you want to apply a vertical force, to make something jump in the air, and let’s suppose you can apply the force at any time, even when you just applied it.

You will have three cases:

Applying the force when the body is not moving: this happens when you apply the force when the body lies on the ground or when it’s in the air, in the moment it finished its “jumping” speed and it’s about to fall down. In this case there aren’t any noticeable difference among applied forces.

Applying the force when the body is moving up: this happens when the body is in the air and still has “jumping” speed. In this case, applying a force or an impulse will sum the “jumping” speed to the applied force to produce a “boost”, while setting the velocity again will just apply the velocity again, no matter the “jumping speed”

Applying the force when the body is falling down: this happens when the body finished its “jumping” speed and it’s falling down. As in the previous case, applying a force or an impulse will sum the falling speed to the applied force, and according to falling speed and applied force, the body will continue falling or jump a little (how little? the difference between the falling force and the applied one). Setting the velocity will just stop the body to fall and make it jumping again, no matter of the falling speed.

The script

This script will generate three tiny boxes. The left one is moved with a force, the middle one with an impulse, and the third one with a set velocity. You will apply forces clicking the mouse

And this is the result:

Apply forces by clicking the mouse in various times, to see the difference among `ApplyForce`, `ApplyImpulse` and `SetLinearVelocity`.

Rate this post: (15 votes, average: 4.73 out of 5)
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

## This post has 13 comments

1. ### Yarden Refaeli

on February 16, 2010 at 3:59 pm

I can’t notice the diffrences between impulse and force. Great post, by the way.

2. ### Guest

on February 16, 2010 at 7:22 pm

the difference between impulse and force is the concept, i think… the impulse is also a force, but applied during a specified period of time… in this case, both are applied in “a click”, (very short time)

3. ### Sergey (with hello from Russia!)

on February 16, 2010 at 10:42 pm

Emanuel, please write how to create a figure of 1/4 parts of a circle or other difficult geometrical form.

4. ### rishabh

on February 17, 2010 at 7:05 am

force and impulse has a big difference

force is applied over a period of time

impulse is applied at once
so if you apply a for of (0,-15) with applyForce
and do the same with apply impulse

there is a noticeable difference

5. ### Box2D Flash game creation tutorial – part 1 : Emanuele Feronato - italian geek and PROgrammer

on February 19, 2010 at 2:16 am

[...] am using the basics of Understanding Box2D applicable forces and Box2D tutorial for the absolute beginners â€“ revamped, which I recommend you to [...]

6. ### darks

on May 5, 2010 at 4:52 pm

Hi, i am trying to use those forces, in a world with 0 gravity, and my objects are never settle no meter what, is there a easy solution for this?

7. ### connor

on June 18, 2010 at 10:25 am

they never settle because there is nothing to stop them since you made the gravity 0…

8. ### Shannon

on July 17, 2010 at 3:58 pm

Because you clear the forces right after you apply them ApplyForces behaves like ApplyImpulse I think. Anyway I tried using the ClearForces() method and apparrently the method doesn’t exist. Thanks anyway I ended up just setting the LinearVelocity of my object to (0.0, 0.0) instead.

9. ### Project: Volvo S60 Pinball game – Things I learnt « Tahir Ahmed's thoughts

on October 12, 2010 at 7:47 pm

[...] forces I had applied on this game on various spots, from handles, to spring, fromÂ tunnel to roads, this entry helped me understand better the available forces in [...]

10. ### Rirara

on January 18, 2011 at 11:40 pm

Great post, thanks. I’m trying to make a game and this is very useful. Thanks!

11. ### jianhualee

on January 30, 2011 at 11:53 am

if you see the sourse code ,you will find the difference of the two methord.

12. ### Caique Barbosa

on May 30, 2012 at 9:27 pm

Please help, I have a super important school project in 2 weeks, and I’m having some problems with Box2D.

I’m using WCK to make things easier, but I still don’t kwno much about Box2D.
First I’d like to know how can I my character move in a constant speed (and don’t speed up). The example I’ve got of BoxMan on WCK uses ApplyImpulse, what makes him speed up. I’ve tried LinearVeolcity, but when I use it, my character is able to walk on air. Gravity doesn’t seem to apply (since he’s holding the left/right key)