How to keep object stay straight vertically (Roly-poly toy)?

Post Reply
User avatar
romanshuvalov
Posts: 4
Joined: Fri May 06, 2016 5:36 pm

How to keep object stay straight vertically (Roly-poly toy)?

Post by romanshuvalov »

Greetings.

I need to prevent vehicles from flipping over and also keep human characters stay vertically. But it should be "soft" so objects can shake in about +/- 30-degree away from vertical gravity axis due to hitting bumps or get impacts from other objects or something so it will look naturally. Note that gravity can change in particular world zones.

Here is illustration:

Image

I plan to measure tilt angle between object and gravity direction and apply opposite torque proportional to this angle. Angular damping should reduce permanent oscillating.

It's good idea? Or Bullet has some kind of built-in functionlity to do it simplier? Maybe you know better solution?

And second question. I haven't started implement character yet, but it looks that btCharacterControllerInterface it not designed for custom gravity vectors, it is correct? So, I plan use capsule for character body and point-to-point-joined sphere as a "wheel" so character can walk (roll) on surfaces. What do you think, will it work? Or you know better scheme?
User avatar
romanshuvalov
Posts: 4
Joined: Fri May 06, 2016 5:36 pm

Re: How to keep object stay straight vertically (Roly-poly t

Post by romanshuvalov »

First problem is solved. Applied up.dot(gravity) torque around up.cross(gravity) axis. Worked fine for car. I've powered torque value to torque^3 so it pushes softly when body is almost straight and hardly when it tilted more or flipped over. Didn't tested on character yet because character is not implemented (second question is still actual), but I think for character, torque value should be powered to something like torque^(1/3) with saving sign: sign(torque) * (abs(torque))^(1/3).
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to keep object stay straight vertically (Roly-poly t

Post by Basroil »

Basically your issue here is aninverted pendulum, where your body is the pendulum. Pretty easy in theory, but when you try to add compensation for rotational effects, collisions, etc, it can be more of an art in tuning. Throw in a bit of angular damping and it shouldn't be too difficult to get down for one case.
Post Reply