Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behaviour of rigidbodies with high mass #60

Closed
Dev-MarkoF opened this issue Feb 17, 2023 · 1 comment
Closed

Incorrect behaviour of rigidbodies with high mass #60

Dev-MarkoF opened this issue Feb 17, 2023 · 1 comment
Labels

Comments

@Dev-MarkoF
Copy link

Dev-MarkoF commented Feb 17, 2023

Hi,
when having a simulation with bodies above a certain weight (around 200kg+) bodies start to go through each other, and jitter,
especially through static bodies.

The more the weight is increasing the more go through each other until eventually at less than 2 tons, most go through.
The simulation in general seems odd, the bodies seem to rotate too fast for their high mass.
This is for all shapes but spheres, so i suspect it's something within the solving that is different for them.

You can easily reproduce it in the OIMO demo.

Steps to reproduce

  • basicDemo, within OimoUtil.hx add random weight to bodies, after shape creation,
    in AddRigidbody:
// the higher up cubes get a higher weight to simulate different weights colliding with each other
massD.mass = 1 + ((center.y < 6 ? 10 : 500));
body.setMassData(massD);
w.addRigidBody(body);
trace("Center :", center, " mass: ", body._mass);

rebuild.

Known things, already figured out,

it does not occur, when setting the rotational factor of the bodies to 0 on all axis, or even a very small number,
the best result i seem to get when dividing the rotationFactor by the mass.
It seems to be generally a better simulation when (it also looks a little slow motion)

body._rotFactor = (new Vec3(1 / body._mass, 1 / body._mass, 1 / body._mass));

The simulation does look near of what i expecting to see, comparing it to e.g. Unity
where, the bodies with high weight that drop onto bodies of lower weight would just push them away, while in the end the heaviest lie in the middle. Similar to a controlled explosion of a house in a demolition.
It looks simlar but not fully correct either.

I tried to increase the solver iterations to no avail, with 500 iterations, it looks better but still a lot different and is using too much compute power for such a simple example, and without changing the rotation factor, bodies still fall through above a certain weight (e.g. 10-50 tons).

But the rotation factor changing as described above does improve the simulation significantly, although not perfectly, so there seems to be a miscalculation somewhere. This fix also results too often in bodies stopping to rotate even though they should, because they go into sleep.
Especially when the rotation is slowed down shortly before the inertia is kicking back in, e.g. a body that should roll over but stops shortly before reaching the highest point where the mass would tilt it over but the current momentum is not high enough to not trigger sleep. Because the last bit is obviously a small rotation before the momentum is gone and mass would pull it down again.

Therefore my simple fix approach is not correct, but i can't determine the general bug that is at work here.

So i suspect it's either a miscalculation on something like inverseMass in some case, because it seems mass dependent but only above a certain weight.
Or it's somewhere where something is scaled with a rotational factor but should instead by scaled by mass.
It's probably in a solving step, because solvers differ between any shape and spheres, and spheres seem to work relatively correct.

Tried to solve it myself, but i'm not yet able to wrap my head around all the inner workings of OIMO.
I would be nice if you could also look into it.

@Dev-MarkoF Dev-MarkoF changed the title Incorrect behaviour of rigidbodies with high weight Incorrect behaviour of rigidbodies with high mass Feb 28, 2023
@saharan
Copy link
Owner

saharan commented May 16, 2024

A light object sandwiched by heavier objects causes unstable behavior in general, and it's very difficult to deal with such high mass ratios in contact solvers.

Generally speaking, you should avoid situations where three or more rigid bodies collide with each other with 1:10 or a worse mass ratio, otherwise rigid bodies may start to jitter. This is true for all kinds of physics engines, although the capability varies between them.

In OimoPhysics, enabling Nonlinear Gauss-Seidel option may improve the situation. Try setting Setting.alternativeContactPositionCorrectionAlgorithm to PositionCorrectionAlgorithm.NGS.

Rotational movements are especially hard, because they're non-linear and you may mitigate jittering by increasing inertia tensor of rigid bodies. See my blog post also: https://blog.oimo.io/2022/08/28/calm-joints-down-en/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants