ApplyImpulse vs. ApplyForce

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
troygilbert
Posts: 10
Joined: Tue Nov 27, 2007 4:08 pm

ApplyImpulse vs. ApplyForce

Postby troygilbert » Mon Jan 07, 2008 1:26 pm

I figured this had been asked before as a few people seem confused on it, but searching the forums didn't reveal anything, so here goes...

ApplyImpulse immediately modifies the velocities of a body, while ApplyForce adds to "force" variables that are applied during the world's step.

Coming from APE (Actionscript Physics Engine) I kinda figured that the difference between the two was whether or not they factored in mass (APE has a addMasslessForce and an addForce that do this). Since ApplyImpulse was the "quickest" to affect objects, I figured it must not factor in mass.

But, looking at the code it's clear that *both* of them factor in mass (they both are multiplied by invMass before being used).

The difference I do see, though, is that ApplyImpulse modifies the velocity of the body (with respect to mass) instantaneously, while ApplyForce modifies the velocity of the body (with respect to mass) *in terms of time passed*. In other words, ApplyForce factors in "dt", which is why it's calculated in the step function. As a result, ApplyForce has about 1/30th (or whatever your physics step is) of the apparent affect as ApplyImpulse.

That makes sense (I guess)... ApplyForce is kinda abstracted away from time and is useful for applying continuous forces, while ApplyImpulse is really just a helper for incrementing velocities with respect to a body's mass.

But, I may be missing something, as I've not looked through all of the code and have no idea if there's more math at play that I'm not seeing/noticing. I'm also not well-read-enough on physics to know whether force vs. impulse are totally apparent terms for those in the know! ;-)

troygilbert
Posts: 10
Joined: Tue Nov 27, 2007 4:08 pm

Re: ApplyImpulse vs. ApplyForce

Postby troygilbert » Mon Jan 07, 2008 1:30 pm

Well, I may have answered my own question...

I just checked Wikipedia's entry on "impulse" and basically got the impression that "impulse" is assumed to include "dt", that is it is instantaneous and does not occur with respect to any specific time interval. Force, on the other hand, is an amount of energy applied along a vector over a given amount of time (dt in our case).

So am I understanding these terms correctly?

Noya
Posts: 6
Joined: Thu Dec 20, 2007 7:29 am

Re: ApplyImpulse vs. ApplyForce

Postby Noya » Mon Jan 07, 2008 1:41 pm

troygilbert wrote:So am I understanding these terms correctly?


Yes, you're right. There is the simple formula: p = F * s (where p is the change of impulse, F a force and s the time, here dt). That means applyImpulse(10) and 10 seconds applyForce(1) will result in the same velocity for the body. To my best knowledge, an impulse is just an incredible huge force over a really short amount of time, and is used to describe collisions in a simple way.

Boing
Posts: 52
Joined: Mon Apr 28, 2008 3:07 am

Re: ApplyImpulse vs. ApplyForce

Postby Boing » Mon Jun 09, 2008 10:54 am

Hmm... Does that mean that the impact of applyForce depends on my timestep?

For example:
If I call world.step(40, 10) at time 000, then applyForce, and then at time 060 world.step(60,10)
the force impact would be 50 % more than if
calling world.step(40, 10) at time 000, then applyForce, and then at time 040 world.step(40,10)?

(I know, I know, using a variable timestep is not recommended but I didn't have a choice...)

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: ApplyImpulse vs. ApplyForce

Postby ewjordan » Mon Jun 09, 2008 1:28 pm

change in momentum = impulse = force * time

So yup, if you apply the same force for 60 time units, it will change the momentum 1.5 times as much as if you applied it for 40 time units.

Something like a player jumping is best handled as an impulse, because it should happen in one moment, and the jump height should be constant regardless of your time step. A rocket pack, on the other hand, is best done as a force, because it happens over an extended time, and the change in momentum over a single frame should be relatively small.

Boing
Posts: 52
Joined: Mon Apr 28, 2008 3:07 am

Re: ApplyImpulse vs. ApplyForce

Postby Boing » Tue Jun 10, 2008 12:50 am

Okay, and with the execution of the following step the impact of applyForce is finished so that you need to apply the force before every step, right?
Or does an applied force have influence on more than the following step?

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: ApplyImpulse vs. ApplyForce

Postby ewjordan » Tue Jun 10, 2008 1:30 am

You're correct, if you want to keep applying a force, you need to apply it every step, it gets cleared otherwise.

Boing
Posts: 52
Joined: Mon Apr 28, 2008 3:07 am

Re: ApplyImpulse vs. ApplyForce

Postby Boing » Tue Jun 10, 2008 1:33 am

Thanks, I got i now :)

6hearts
Posts: 9
Joined: Sat Nov 24, 2012 9:04 am

Re: ApplyImpulse vs. ApplyForce

Postby 6hearts » Fri Jun 07, 2013 11:39 pm

I have a similar question.

If I have a variable frame rate,
and to get a consistent rocket pack boost,
should I include dt in the force?
Eg. use something like ApplyForce(0,10) or something like ApplyForce(0,10*dt)?


Return to “General Discussion”



Who is online

Users browsing this forum: No registered users and 3 guests