• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
16
Question by Clonkex · Apr 27, 2014 at 11:41 PM · physicsforcemode

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
41
Best Answer

Answer by Clonkex · Nov 14, 2015 at 12:37 PM

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Clonkex · Nov 14, 2015 at 01:00 PM 0
Share

If someone reckons this answer isn't correct in any way, please say so and explain why you say that. Thanks!

avatar image mgto · Jan 12, 2016 at 07:26 AM 0
Share

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

avatar image svendkiloo · Mar 02, 2016 at 07:40 AM -1
Share

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.

avatar image HeavyStorm · Mar 09, 2016 at 07:29 PM 0
Share

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.

avatar image oscarAbraham · Jun 07, 2019 at 07:26 PM 1
Share

This gets on top results on google, so I thought I'd clarify something. In spirit, this is right, but not in maths:


So the formula for force is force = mass * acceleration, that can be understood also as force = mass * (distance / time^2) When we input a force to the function, we are not using the formula like that, though. We already know the value for force, what we need is the value for acceleration. So the formula we are using is acceleration=force/mass.


For example, if our force is 5 and our mass is 1, then we get that acceleration = 5 / 1. So, Acceleration would be 5. That means our object's velocity would be augmented by 5. The problem is that we don't know over how much time our velocity would be augmented that much. Unity uses seconds as a time unit, should the velocity change be applied over a whole second? On the other hand, we are calling the function right now, to simulate what happens over a specific timeStep, should the velocity change be applied over this timeStep?


In Force mode, the value that we pass is in newtons. A newton is equal to 1kg * 1m/s^2. That means that if this force is applied to an object with a mass of one kilogram over one second, its velocity will been have augmented by one meter per second. Since our function is calculated on the fixed time step, the object's velocity will only be augmented as if the force was applied over that amount of time. In our previous example, if the fixed time step is .1 seconds, the velocity would be augmented by 5*.1, that means .5.


In Impulse mode, we say to the function: "Whatever the time step, I wan't the velocity change that would be applied in a second to be applied NOW". So our value is passed in units of 1kg * 1m/(s*timeStep). That means that if this force is applied to an object with a mass of one kilogram over one timeStep, its velocity will been have augmented by one meter per second. In our example, the velocity would be augmented by 5 each time the function is called.


Another way of thinking about it is that acceleration = velocityChange/time, that's why time is squared in the answer's formula, because distance/time/time = distance/time^2. Anyway, that means that velocityChange = acceleration*time. So in our example, if we are using Force mode, our time is .1 seconds (so it's 5*.1); but, if we are using Impulse mode, our time is 1 timeStep (so it's 5*1).

avatar image
19

Answer by Jeff-Kesselman · Apr 27, 2014 at 11:47 PM

Okay, basic physics, Force = Mass * Acceleration

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.

This is all explained on the web pages https://docs.unity3d.com/Documentation/ScriptReference/ForceMode.html

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Clonkex · Apr 27, 2014 at 11:51 PM 1
Share

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?

avatar image Jeff-Kesselman · Apr 28, 2014 at 12:26 AM 0
Share

Again, the answer si in the docs:

" 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.

avatar image Clonkex · Apr 28, 2014 at 12:41 AM 0
Share

Ok...still not sure I totally understand how this works, but it doesn't really matter since I now understand what happens as a result of each method. Thanks! :)

avatar image Clonkex · Nov 14, 2015 at 12:39 PM 0
Share

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

avatar image Clonkex · Nov 14, 2015 at 12:45 PM 0
Share

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.

Show more comments
avatar image
6

Answer by jchangxu · Oct 11, 2014 at 07:13 PM

I had difficulty understanding the 4 modes as well, especially what is the period of frames it applies to. This helped me.

http://www.redshiftmedia.com/gamasutra/Tomasz%20Kaye.%20Understanding%20ForceMode%20in%20Unity3D%20(salvaged%20from%20Gamasutra).html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Clonkex · Nov 14, 2015 at 12:40 PM 0
Share

You answer helped me finally solve the mystery. I've posted my own answer in the hopes that it may help other people confused by the lacking documentation of this feature :)

avatar image metroidsnes · Sep 14, 2018 at 06:08 AM 0
Share

The link is broken.

avatar image
3

Answer by Owen-Reynolds · Mar 11, 2016 at 11:36 PM

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:

 rb.AddForce(10*Time.fixedDeltaTime, 0, 0, ForceMode.VelocityChange);
   or
 rb.AddForce(10, 0, 0, ForceMode.Acceleration);
 // ForceMode.Acceleration multiplies by fixedDeltaTime

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.)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ykravchik · Mar 15, 2017 at 08:52 AM 2
Share

Best explanation! I'll just add to illustration:

     //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);

avatar image
3

Answer by LouisHong · May 22, 2018 at 01:52 PM

ForceMode.Acceleration is ForceMode.VelocityChange but mutiplied by Time.fixedDeltaTime


ForceMode.VelocityChange just changes velocity by force parameter


ForceMode.Impulse changes accelerations by force / mass


ForceMode.Force changes acceleration by force / mass * Time.fixedDeltaTime


They should just write this as the unity documentation for ForceMode, hope you found it useful

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrLeaky · Feb 06, 2019 at 09:05 AM 1
Share

Exactly; this is a great way to summarize it. The documentation is totally confusing, and their bloated, unreadably formatted (i.e. no proper syntax highlight) example code is not helpful at all.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble with spring platform 0 Answers

ForceMode.VelocityChange vs. simply adding to .velocity 0 Answers

Foces only change during collision 1 Answer

Trying to Understand Rigidbody ForceMode Derivation 3 Answers

Addforce - bug with jump 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges