Problems with cone twist constraint and body sleep

Post Reply
Shephf
Posts: 4
Joined: Sat Apr 25, 2020 11:16 am

Problems with cone twist constraint and body sleep

Post by Shephf »

I'm working on a 3D engine and currently integrating bullet physics, it was smooth so far, but I've came across a couple of strange behaviors, I'll
call them sleep bug #1, #2 and #3 here. I've also made a couple of videos that demonstrate them, so:

sleep bug #1:

Setup is: 1 static body and 3 dynamic bodies, connected with cone twist constraints. Almost all of the parameters are default (check out the video).
When the bodies are inactive everything is ok, when I give one body a small velocity it all moves and then comes to rest, however, if I give it a big enough velocity the whole thing will never come to rest, even cutting off two bodies doesn't help:

https://www.youtube.com/watch?v=Kqi2XbH4xp8

I've played with all the dampings and factors a lot, but noting seems to work.

sleep bug #2:

The same setup from #1, when I cut off the two bodies the whole thing sometimes does go to sleep, but at a very strange position:

https://www.youtube.com/watch?v=C65TWuHiuQw

The body freezes at a funny angle, it feels like it should be moving and only calm down when it's upright.

sleep bug #3:

The same setup, but if I use kinematic body instead of static then the joint misbehaves after kinematic body goes to sleep:

https://www.youtube.com/watch?v=u3fc07OP3M0

In this setup kinematic body doesn't move, when it does move everything is fine. In my game I want to have things like moving platforms with stuff attached to them via constraints, these platforms will sometimes come to rest and I want them to fall asleep in that case, but due to that bug all of the joint bodies will slowly "fall down"
Shephf
Posts: 4
Joined: Sat Apr 25, 2020 11:16 am

Re: Problems with cone twist constraint and body sleep

Post by Shephf »

So, sleep bug #3 seems to disappear if I comment out:

Code: Select all

if (body && body->getActivationState() != ISLAND_SLEEPING)
in btDiscreteDynamicsWorld::saveKinematicState. I'm not 100% sure that this change is correct though. In general, it looks like constraint solver
modifies velocity of kinematic objects, when kinematic object isn't sleeping in does:

Code: Select all

btTransformUtil::calculateVelocity(m_interpolationWorldTransform, m_worldTransform, timeStep, m_linearVelocity, m_angularVelocity);
in btDiscreteDynamicsWorld::saveKinematicState and that resets velocities to 0, since world transform isn't changing (getMotionState()->getWorldTransform(m_worldTransform) always returns the same thing). When kinematic falls asleep this no longer happens and last applied velocity doesn't get reset and this screws up the constraint.
Shephf
Posts: 4
Joined: Sat Apr 25, 2020 11:16 am

Re: Problems with cone twist constraint and body sleep

Post by Shephf »

Regarding sleep bug #1, things became a bit better when I set body linearDamping to 0.05 and angularDamping to 0.85. Though I don't like this solution much, such dampings are quite large, i.e. if I "cut" the joint body behaves a bit floaty, but I guess I can change dampings during simulation, so this is a viable workaround. But I still want to know if there's a better way to handle this.

And regarding sleep bug #2, I've made things a bit better by setting:
m_linearSleepingThreshold = 0.5f;
m_angularSleepingThreshold = 0.5f;
Body can still freeze at a funny angle, but it's less noticeable.
Post Reply