🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Sequential impulses connected rod chain constraint

Started by
0 comments, last by Vexal 6 years, 1 month ago

I have a question about the constraint for a chain of connected rods.  I am using C = P2 - P1 to be the constraint, where P2 and P1 are 3d vectors representing the attachment point of the constraint on each rod.

My solver kind of works, but is not very stable. I have debugged it with just a single rod connected to the world to test, a scenario I believed should be solvable with a single iteration, but it still has problems.

After stepping through, it looks like the derivative of the constraint is only valid at the exact current values of P2 and P1.  It appears to correctly solve for an impulse which makes the derivative of C zero, but that derivative is no longer accurate as soon as the objects move at all.  The problem is that for any velocity, adding the final velocities to the positions of the objects at the end of the frame will move the objects enough that it will have still landed in a state that violates the constraint, despite having solved for an impulse that made the derivative zero.  I am wondering if this is indicative of a misunderstanding of the algorithm on my part, or if there is something one is supposed to do to make it so instead of solving for a locally-valid derivative, it finds a solution which is not the exact impulse to make the derivative zero, but instead enforces that at the end of the timestep, adding the velocity to the position still results in the new position not violating the constraint.

The bias term also does not exactly fix it because that is applied with a scale factor, and it is calculated before the objects move for the frame and does not account for the final velocity of the object.

 

This is a video showing what is going wrong.  The beginning of the video shows stepping through the simulation one frame at a time after applying a force directly perpendicular to the object's center of mass. It shows how it spins around the connection point rather than be perfectly attached to it.  The end of the video shows the rotation without stepping one frame at a time.

EDIT: Changing it to subdivide the timestamp and run several frame updates per frame made a very large difference in stability (this change is not reflected in this video), but I am still wondering if there is a better way.

 

This topic is closed to new replies.

Advertisement