Hello everyone, I am trying to get a better understanding how the ForceMode formulas work (not “What they do”) with Rigidbody.AddForce().
Take for example Acceleration and VelocityChange, both of which ignore mass to makes things more simple. Lets also say that my added velocity is (0,0,0.1).
I observe that Acceleration will take 1 second to apply the full force, and VelocityChange will do the same each Fixed Update. What I don’t understand is the formula used to derive the difference (and I fully appreciate I just may be doing / understanding the math completely wrong).
Acceleration uses distance/time^2 (0.1/0.02^2). Which, using the vector above gives (0,0,250)…huh?
VelocityChange uses distance/time (0.1/0.2). Which, using the vector above comes to (0,0,5)…again, what?
I don’t understand how the values outputted by the formula ends up moving the rigidbody in the way it does. Any clarification is greatly appreciated.
ForceMode.VelocityChange does exactly what the name suggests. So those two lines do exactly the same:
// The passed "force" parameter is in m/s which is added instantly to the velocity
rigidbody.AddForce(Vector3.forward*1.0f,ForceMode.VelocityChange);
rigidbody.velocity += Vector3.forward*1.0f;
ForceMode.Acceleration is ment to be applied every FixedUpdate. So the result you get after 1 second is the same as VelocityChange. The next two lines are exactly the same:
// The passed "force" is in m/s². If applied every fixed frame the accumulated velocity will increased by "force" m/s every second
rigidbody.AddForce(Vector3.forward*1.0f,ForceMode.Acceleration);
rigidbody.velocity += Vector3.forward*1.0f * Time.fixedDeltaTime;
ForceMode.Force and ForceMode.Impulse just do the same but also divide by the mass of the object:
// "force" is in newton (kg*m/s²)
rigidbody.AddForce(Vector3.forward*1.0f,ForceMode.Force);
rigidbody.velocity += Vector3.forward*1.0f * Time.fixedDeltaTime / (rigidbody.mass);
ForceMode.Impulse:
// "force" is a impulse / momentum which is in kg*m/s
rigidbody.AddForce(Vector3.forward*1.0f,ForceMode.Impulse);
rigidbody.velocity += Vector3.forward*1.0f / rigidbody.mass;
You’re confusing the difference between a unit and a formula. It might be helpful if you understood the basics of physics, aka classical mechanics. You might also want to read the documentation of each of the force modes more carefully. ForceMode.Acceleration is over a period of time, while VelocityChange is instance (which is not what you described).