DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.54k stars 224 forks source link

Total force differs with update timestep? #343

Closed ghost closed 1 year ago

ghost commented 1 year ago

I found this in the documentation:

"Note that when you call the previous methods, the specified force/torque will be added to the total force/torque applied to the rigid body and that at the end of each call to the PhysicsWorld::update(), the total force/torque of all the rigid bodies will be reset to zero. Therefore, you need to call the previous methods during several frames if you want the force/torque to be applied during a certain amount of time."

I take this to mean that a different total force will be applied to a body depending on the timeStep given to PhysicsWorld::update().

What happens if a force is given to a body during the simulation, such as in a collision? I presume that will not create different behaviour based on the update timeStep.

DanielChappuis commented 1 year ago

The applied force/torque is applied (integrated) exactly as other external forces (like gravity).

At each call of the PhysicsWorld::update() method, the new velocity is computed this way:

$v_{i+1}= v_i + dt \cdot 1/M \cdot F $

where $v$ is the velocity, $dt$ the timestep, $M$ the mass and $F$ the external force.

So it means that if a force of 9 $N$ is applied over 1 second. If the timestep is $1/60 s$, there will be 60 updates during that 1 second, and therefore the final velocity will be 9 $m/s$ if the mass of the body is 1kg.

I hope this helps.

ghost commented 1 year ago

Thank you Daniel.