Rigid body not able to stand still

N_K
Posts: 14
Joined: Mon Jun 04, 2012 11:40 pm

Rigid body not able to stand still

Post by N_K »

Hello all.

Again, I have a problem that must be trivial to fix, but I was not able to do so on my own...

I have an upright (limited angular factor) rigid body that can be moved around. I have a camera which is moved by around by following this body. However, sometimes, the rigid body is not able to stand still, it does a very minimal bounce along the Y axis, as it would try to penetrate the ground. And since the camera follows this body, it shakes vertically as well because of this...

The shape of the rigid body doesn't seems to matter, I've tried all the diferent shapes, and this happened with all of them. Neither it seems to depend on the situation: sometimes it's absolutely fine after falling or when on a slope, and sometimes it shakes when it has been moved minimally on a completely flat, even surface.

When I enable deactivation, it stands still (of course), but then after it fallen asleep, I'm not able to move it any more (of course). I'm sure it can be stopped somehow since it happens randomly, sometimes it's resting absolutely fine.

Any ideas about this? Thanks in advance.
c0der
Posts: 74
Joined: Sun Jul 08, 2012 11:32 am

Re: Rigid body not able to stand still

Post by c0der »

How are you making it sleep, are you updating sleep state after updating the position? Perhaps you can play around with the sleep epsilon value if the body keeps moving with low kinetic energy.
N_K
Posts: 14
Joined: Mon Jun 04, 2012 11:40 pm

Re: Rigid body not able to stand still

Post by N_K »

Since it's an interactive object, it never sleeps (otherwise I would loose control over it). To make it stop when there's no input, I reset it's position to Vector3(0, getY, 0) in each frame before the input processing takes place. getY is getGravity().getY(), and I think the issue could be there. However, as I said, sometimes it stands in place perfectly, and this behavior seems to happen completely randomly, regardless of the physics situation.
c0der
Posts: 74
Joined: Sun Jul 08, 2012 11:32 am

Re: Rigid body not able to stand still

Post by c0der »

Ah yes, my bad, gravity will always act on it since its player controlled. However, if you do put it to sleep and wake it up when you manually apply player forces (with a manual call to a setAwake function), thats 1 idea. Or apply impulses over several iterations if you're using those to resolve collisions. Box2D lite has a technique of warmstarting that seems to stabilize objects with resting contact. Get box2D lite from Erin Catto's 2009 presentation.