How to balance an object

whtitefall
Posts: 1
Joined: Thu Mar 05, 2020 9:48 pm

How to balance an object

Post by whtitefall »

Hi

I'm new to Bullet, I'm trying to move a rectangle on the surface,
however, the rectangle will fall when I try to move it,
how can I apply the gravity so that the rectangle stand still when I'm moving it.

I'm using ammo JS, but I did not found any useful documentation on it, so I'm wondering how that will be implemented in Bullet

Thank you!
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to balance an object

Post by drleviathan »

Since the rectangle falls over I assume it is a dynamic box. You say you would like it to "stand still" while it is being moved. I assume you mean you want it to remain standing up while it is moved.

If you push a dynamic box at the center while it is resting on a floor then I would expect friction to apply at the box's contact points and I could see how it might fall over.

How do you "try to move" it? Do you applyForce()? give it a non-zero velocity? apply a constraint?

I can think of several ways that might work for you:

(1) Rather than push the box around, just slam its transform to where you want it. In other words: make the object effectively kinematic when you move it.

(2) Push the object around but before you start: measure its orientation and then as you push it also: zero its angular velocity and also slam its orientation to the measured value at start-of-push.

(3) If the box should not rotate at all while moved, but should be allowed to tumble otherwise: temporarily set its inverse inertia tensor to zero, push it around, and then when you're done restore the inverse inertia tensor.

(4) If the box should be allowed to twist about the vertical but never ever tip over then you can perform what I call "the inverse inertia hack" where you zero the two other axes of the inverse inertia and only keep the vertical axis non-zero. This trick works well for "character bodies" that should always remain upright.