Jump to content
  • Advertisement
Sign in to follow this  
d000hg

Managing persistent forces on a body

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game engine, I keep a list of every physical body which forces can be applied to. I also have an integrator object which updates the position etc of each body. The problem comes because I'm dealing with a car. As part of the integration, forces are made on the car from the wheels acting against the ground. After doing an integration step, these forces must be zeroed before the next step, else the force from every step would be summed over time! But because I'm using an RK2 integrator, effectively 2 steps must be done each update. After doing the first, forces must be zeroed. This is all OK, until I want to add some other forces in. For instance I want to add a large drag force proportional to how much of the car is under water. What basically happens is that I add this force before calling the integrator to do its stuff - but then as part of zeroing the internal forces it also removes the external force. How can I remedy this? I've not seen such a problem with real physics engines. I guess when adding forces to a body, it could maintain a list of each separate force on the body rather than summing them, but this seems wrong.

Share this post


Link to post
Share on other sites
Advertisement
Well, if you have a single callback-type function that is called to set the forces on each body, this function can explicitly:

1. Zero any previously accumulated forces
2. Walk through any potential sources of force (drag, suspension, gravity etc) and get them to add to the body force.

For example, your main rigid-body class (assuming C++ and you use inheritance to define rigid body behaviour) might have a virtual function called "SetForce", and this would call functions called "AddForces" to all the constituent parts (like springs, aerofoils etc).

This way, if you have an empty SetForce callback function (e.g. the default implementation), then if there is a constant force on the object it just stays there. I don't think the internal physics engine code should be zeroing the force, since these forces are external to the internal physics code.

If you're using forces for internal reasons (e.g. resting contact) in your physics engine code, then it might be appropriate to have a separate accumulator for these forces - then your rigid body would have two force variables for "internal" and "external" forces. The internal code would then have the right to zero/set the internal forces when appropriate, without affecting the external forces.

Just some ideas - I don't claim this is a perfect solution!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!