# Self-righting fallen over critters

This topic is 2749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. I have some critters that just love to fall over onto their side, back, or even ends (i.e. they are modeled as cuboids).

At the moment I correct this by instantly altering their orientation when the dot product of surface 'up' and agent 'up' is less than some number (e.g. -0.5), so that they can fall over only so much before they are insta-righted.

Obviously this looks nasty. Plus in the border cases, where the dot product isn't quite low enough, they can still fall over and don't get self-righted.

So, I need a way to have the critters automatically roll back onto their feet. How can I do this? The way I see it there are two problems:

1) How to determine the best rotation axis (e.g. better to roll on their back than head-to-tail)?

2) How to work out the magnitude of torque required to overcome the physics engine, whilst not being too much that has them flipping end over end?

Any hints much appreciated!

Cheers,

##### Share on other sites
Hmmm. A common way this is done in commercial games is to run a special keyframe animation that will put the character back up right. So, if the character falls on its back, run an animation "on back to standing upright." If the character falls on its face, run an animation "on face to standing upright." Relatively simple game logic would be used to decide which animation to run.

Since your characters are simple, you could possibly do something procedural without a whole lot of work. I'm thinking of determining the quaternion rotation that would put them up right, and slerp from their current fallen orientation into the correct rotation over a number of frames. The tricky part would be figuring out in which direction to slerp, whether you should first slerp one way, then another way, in two steps, say. As long as you aren't dealing with limbs/arms/legs/whatever that you want to also look natural, a simple quaternion interpolation could work for you.

I think I would initially avoid trying to apply physical forces to upright the characters. If I were doing this, I'd first turn physics off, do the pure animation, reset the initial conditions of the rigid bodies, then turn physics back on. This is pretty commonly done also in games, e.g., switching between purely keyframe animated characters and a physics engine to do ragdoll dynamics. I think it'll be less painful and more successful. I'd at least try this until you get your game more polished. In fact, maybe you never need to do physics for uprighting characters. Would physics actually help your game for this use case? For the uprighting part, my guess is it probably won't help, at least not much.

Let us know what you decide or how you proceed!

##### Share on other sites
Interesting post grhodes. This is something I'm interested in too.

For situations like this, with 2D work and some 3D work I tend to take a hacky physics approach, just manipulating the physics any way possible to correct the object.

But this approach can be glitchy and unpredictable, so you're right, a dynamic approach sounds a lot better, switching between canned animation and physics, and resetting the physics model.

##### Share on other sites
Model them, for the purposes of physics (if not of graphics), not as uniform-density cuboids, but instead as spheres with very low centers of gravity? Can your physics engine "just do" this? All you need is a way to make "right side up" be the only stable configuration.

• 36
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631359
• Total Posts
2999545
×