RevoluteJoints cause entities to "wobble" back and forth

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
coNNecTT
Posts: 3
Joined: Thu Jun 30, 2016 11:10 am

RevoluteJoints cause entities to "wobble" back and forth

Post by coNNecTT »

Hi, I have this structure attached to a point in world with RevoluteJoints. After a bit it starts moving back and forth:

https://i.gyazo.com/b1356a109c93cc77a37 ... e6fd38.mp4

Each board has 2 joints attached on top and bottom. Why is this happening? Any solutions? I think I should only allow rotation on one axis, but the "LocalInertiaTensorInverse" approach doesn't work.. Thanks!

EDIT: I think I solved it again.. I just had to decrease the mass of the anchor entities and set the "LocalInertiaTensorInverse" every frame.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RevoluteJoints cause entities to "wobble" back and forth

Post by Norbo »

This and the earlier post's behavior (viewtopic.php?f=4&t=2419) is what happens when the solver cannot find a satisfactory solution. Since it's an incremental solver with a finite number of iterations, it stops with a 'partial' attempt at the answer. So with particularly hard (or impossible) configurations, things go goofy.

Generally, this means one of a few things:
1) The configuration of involved constraints fight each other. If constraint A directly opposes constraint B, and A and B are both very stiff (as constraints are by default), it will be hard to converge to a solution. To avoid this, use the smallest number of simple constraints necessary to achieve a goal, and make sure that any constraints that are used are not incorrectly opposing each other.

2) A relatively heavy object relying on a light object. A light object on a heavy object is perfectly fine, but you won't be able to stably place a 30 ton tank on top of a stack of cardboard boxes. Joints work similarly: a rope composed of a bunch of very light rope entities connected together with a big heavy wrecking ball on the end is one of the worst cases. The rope will tend to stretch, or with overstiff tuning, explode. To avoid this, try to keep heavy objects from relying on very light objects. Where possible, adjust masses to compensate and/or soften the involved constraints by reducing their stiffness and damping coefficients. (Later on, probably down the road after v2.0, I'd like to try out some different kinds of articulated solvers which would handle things like wrecking balls stably by marking them for special handling in the solver. Don't wait on me though :P)

3) Unstable lever arms. Imagine you've got a small and very light object- say, a basketball- but have a constraint attached 10 feet away from the center of it. The lever arm is absolutely massive compared to the small inertia of the basketball. That imbalance interferes with the efficient propagation of forces through the constraint graph, making it hard to solve. Note that in real life, you can't attach stuff to an object 10 feet away from that object- try to hold to the same logic in simulation :) Sometimes, if all other options are exhausted and there still seems to be some rotational instability, scaling up the associated entity's local inertia tensor can help.

4) The constraint structure is really complicated and/or just plain hard to solve. Imagine a vehicle composed of lots of individual pieces and a physical drivetrain moving at high speeds. Check for opportunities to soften constraints. The default constraint tuning is very stiff, which means any constraint interaction will tend to be more difficult to solve. If you don't actually need a constraint to be that stiff, reducing the stiffness/damping coefficients will often improve stability dramatically.

If that's not an option and there is no way to otherwise simplify the constraint system, you're probably stuck with brute force approaches: increasing the solver's iteration count and/or decreasing the time step duration (and stepping more frequently to compensate).

Regarding this situation in particular, it's hard to say for sure which of the above you're running into by visual inspection alone. I'm guessing some mix of mass ratios, lever arms, and constraint configuration issues are in play.

Setting the local inertia every frame is almost certainly not going to do what you want in the long run. When it comes to these kinds of issues, making a change without a full understanding of why it would actually solve the problem will generally result in the problem not actually being solved, even if it looks like it at first glance. It's best to avoid weird hacks like inertia tensor fiddling until they are proven required.

If you want to create a reproduction case of the behavior inside one of the BEPUphysicsDemos simulations, I could take a look and give you more specific advice.
coNNecTT
Posts: 3
Joined: Thu Jun 30, 2016 11:10 am

Re: RevoluteJoints cause entities to "wobble" back and forth

Post by coNNecTT »

Thank you for this really informative post! I would try to recreate and explain my problem better, and the solutions you gave seem like they would be a good starting point to fix this, but it so happens that I'm at this stage where I'm just coding a bunch of game prototypes very quickly, so I won't try these solutions right away... but I'll probably come back to it at some point! Thanks again!
Post Reply