Language

Difference between ForceMode.Force/Acceleration/Impulse/VelocityChange?

What is the difference between the four modes of ForceMode? I don't understand how you can apply a force in multiple ways. For example, if I put my hand on a car and push with a specific amount of force for 5 frames, what's the difference to hitting it with the same amount of force once each frame for 5 frames?

5 Replies

History Lesson (not really)

Ok, so more than a year later I've had the need to come back and attempt to fully understand this problem (as I never really understood what the differences were). After staring at the formulae for a long time and not really getting anywhere, I decided to stare at the page linked by @jchangxu (thanks btw!). After a short while, one phrase jumped out at me: Think of it as 'Force exerted per second'

Instantly I realised I understood the differences. It's actually really simple, but everyone makes it sound so complicated that you assume it's more complicated than it really is. Since no one has yet managed to explain it clearly, here's my attempt from the viewpoint of someone who's only just figured it out.

Incidentally: The official documentation could do with an explanation such as this one since the current explanation in the docs is crappy and doesn't actually tell you anything unless you do the maths yourself, and even then the maths alone doesn't tell you everything about the function.

tl;dr (...or "The Boy That Couldn't Be Bothered")

ForceMode.Force == Force per second
ForceMode.Impulse == Force per frame

There's no actual difference in the way .Force and .Impulse apply the forces, only in how they calculate the amount of force to apply. If you do .Force once every FixedUpdate for exactly one second, you will have applied the same amount of total force as doing .Impulse on just one frame.

Longer Explanation (for maximum understandings)

Say you have an object with a mass of 1. You are applying a force of 5 (the "distance" part of the formula) - i.e. you're passing 5 into your AddForce function with ForceMode.Force. You are using a timestep of 0.1 (i.e. 10 frames per second). The formula inside is this:

mass*distance/time^2

At first I assumed BODMAS applied and did the exponent first, but that didn't seem to work. Then it occurred to me that the actual behind-the-scenes code was probably just doing time*time rather than using any built-in exponent operator. That means the above formula equates to the following:

1 * 5 / 0.1 * 0.1 == 5

Ok, so if you put in 5, ForceMode.Force will apply a final force of 5 per frame. Just to be clear - that's all it does. It won't continue to apply the force for any more frames unless you run that command on each frame. If you DID run that function each frame, it would apply 50 force per second.

Now ForceMode.Impulse:

mass*distance/time

Which is...

1 * 5 / 0.1 == 50

So ForceMode.Impulse is applying 50 per frame.

See how simple that is? The only difference between ForceMode.Force and ForceMode.Impulse is that .Force makes it force per second and .Impulse makes it force per frame. In our case, since our fixed timestep is 0.1, we could simply divide the force parameter by 10 (or multiply by our timestep, 0.1) and .Impulse would give us the same as .Force.

Final note: I intentionally left out ForceMode.Acceleration and ForceMode.VelocityChange because they are identical to .Force and .Impulse, respectively, except that they ignore the mass of the objects. That part is explained pretty well in the docs and doesn't need elaborating on.

Your answer is good but there is one problem in the way you describe the effect.

So ForceMode.Impulse is applying 50 per frame

50 what?

What you are currently doing when using AddForce() is not applying a 'distance' but:

ForceMode.Impulse: you're applying an Impulse in Newton Seconds (Ns)

ForceMode.Force: you're applying a Force in Newton (N)

If you're applying a Force of 5 (or an Impulse of 5) that's it. You don't have to calculate the actual force.

BUT if you want to know how big delta_s or delta_v are (the relative change in distance / velocity) you can use (for example) the formulas you've posted to calculate the values.

So if you have an Impulse of 5 Ns your object will travel 5 * 0.1 / 1 = 0.5 (relative) units after applying the impulse.

If you have a Force of 5 N your object will travel 5 * 0.1^2 / 1 = 0.05 (relative) units after applying the force for one frame and 0.5 (relative) units after applying it for 10 frames and 5 (relative) units after applying it for 100 frames etc.

I always write 'relative' because it always depends on the start conditions how the objects absolute movement will look like

I think Jeff's answer is a better, clearer and more concise answer to the question you asked, even if it's not the answer you were looking for. I think it's a more useful "accepted answer" for other people who are looking for an explanation of what the difference between the four ForceModes are.

I'm pretty sure where you typed 1 x 5 / 0.1 x 0.1 you meant 1 x 5 / (0.1 x 0.1), after all the math is based on the square of delta time, which would be 1 x 5 / 0.1^2. So the total force applied would be 500, not 5.

This means if you apply the same force to something with twice as much mass, the resulting change in acceleration is half as much.

Force Add a continuous force to the rigidbody, using its mass.
Does what the formula says. The force is applied evenly across the period of the frame which is how you normally push on something.

Acceleration Add a continuous acceleration to the rigidbody, ignoring its mass.
Just adds the force vector to the current object acceleration without dividing it by the mass

Impulse Add an instant force impulse to the rigidbody, using its mass.
As the description says, this is the entire force, divided by mass, added all at once. Its for simulating things that accelerate very suddenly like explosions

VelocityChange Add an instant velocity change to the rigidbody, ignoring its mass.
This is like Impulse but does not divide the force nby the object's mass.

But...what I don't understand is how a force can be applied continuously when the physics is only calculated in set steps. Surely it has to be applied all at once in the step that the function is called from?

" In this mode, the unit of the force parameter is applied to the rigidbody as mass*distance/time^2."

The force is calculated as being applied over the distance traveled so that in the intervening time, it accelerates to the final speed. This means it will not move as far as if the force changed the velocity at the start of the duration and the object moved at that final speed over the entire duration, which is what an impulse would do.

I unaccepted your answer because I wrote my own after I figured it out for myself. You clearly misunderstood why I was confused before since your answer didn't really answer my question, but it's all good now since I've worked it out :P

To be clear, my confusion revolved around the fact that you didn't explain what "continuous" meant. I sounded like you meant the force continued to be applied for a certain number of frames after you called the command, or that it applied a decaying amount of force over a number of frames. That kind of thing. Not explained anywhere and super confusing if you don't know any better. In the end I decided you must mean the physics engine treated the force differently, so a .Force would be calculated as though it were a constant force between one timestep and the next, and .Impulse would be calculated as though it were an instantaneous force at the start of the the timestep... or something. I still didn't understand how that could work, though, so I gave up on trying to figure it out.

The trick with ForceModes and all the physics talk is it wasn’t written for us. It’s from general physic simulators, where you don’t talk about framerates and don’t script, but you know Newtonian physics really well. When Unity borrowed the Physics Engine, those terms just came with it.

So the confusing part is two things. One, it seems like they’re using that strange Physics language because there’s no easier way to explain it (not true.) The other is how using it is pointlessly awkward. AddForce really is written in a bad way for regular game designers.

All AddForce ever does is change your speed, as a 1-time thing. Some of the options say stuff about “force over time” — we can ignore that. One ForceMode option divides by the framerate, another divides by how much you weigh. The other two divide by both, or neither.

That seems insane, to have options for math we can easily do ourselves. We all know if you want to add 10 per second, you add 10*Time.fixedDeltaTime every frame in FixedUpdate(). If you want to divide by the weight, you put 10/rb.mass. If you want to use both — it’s math, you just type it all out.

It happens that ForceMode.VelocityChange is the “just add it” option.
To speed up by 10/second we could put either of these in FixedUpdate:

To a Physics guy, that star symbol and the Time-dot part is super-confusing. But they understand Acceleration means you’re only giving it a little fraction of 10 right now.

Or suppose this was in a non-Unity system with a drop-down number picker — you couldn’t even put an equation after the 10, and would have to use the right ForceMode.

The last mystery is why the default is the most complicated option. If you just use rb.AddForce(10,0,0) it uses ForceMode.Force, which divides by the frameRate and your weight. It’s that way because it was designed by physicists —- that’s the real way pushes work.

They don’t understand that we don’t care about the real way.

Even the command-name is needlessly Physics-based. AddFORCE? Why not just AddVelocity, which is what it really does? Again, to a Physicist, using a Force is more natural. To us, giving just a speed is normal (like giving a boulder a speed of 10, no matter what it weighs.)

//all these functions produce the same effect
//number will be just added,
// so we usually want to multiply by dt by ourselves
rb.AddForce(10*dt, 0, 0, ForceMode.VelocityChange);
//number will be multiplied by dt inside
rb.AddForce(10, 0, 0, ForceMode.Acceleration);
//number will be <divided by mass AND multiplied by dt> inside
rb.AddForce(10*mass, 0, 0);
rb.AddForce(10*mass, 0, 0, ForceMode.Force);
//number will be <divided by mass> inside
rb.AddForce(10*mass*dt, 0, 0, ForceMode.Impulse);