Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I need insect-like agents that have fallen/rolled on their back/side to naturally re-orient themselves. The agents are modeled as simple cuboids in the physics engine (Bullet) to approximate an ant-like shape.

At the moment I correct the orientation by instantly altering it when the dot product of surface 'up' and agent 'up' is less than some number (e.g. -0.5). Thus the agents can fall over only so much before they are insta-righted in the blink of an eye.

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?

[Full disclosure: I originally posted this question on gamedev.net, to no response. I also posted in StackOverflow, but deleted the post when this stackexchange was recommended instead]

share|improve this question
    
Sorry, maybe not the most helpful... but it seems like what would be intuitive would be if the critters rocked back & forth to right themselves. Or if you had a static animation sequence showing them going from on-their-backs to upright. But maybe I'm missing your point entirely :? –  Mordachai Dec 8 '10 at 16:21
    
Rocking back and forth is an option, I hadn't really considered that, and would look most natural and be more realistic. However, I'm not sure of the math to do this. Animation isn't really an option, as this is mainly a simulation rather than game per se, and interaction with other objects would be possible during the self-righting procedure. –  Dave Dec 8 '10 at 16:24
    
I'm sure in the past I've seen pseudo-physics in racing sims that will roll a car back onto its wheels in a natural looking way. This is what I've had in mind trying to solve this problem –  Dave Dec 8 '10 at 16:26
2  
With the rocking, when angular velocity is below some limit and not right-side-up yet, apply an increasing force to rock back. Should get right-side-up without flipping in a couple tries. –  Zan Lynx Dec 8 '10 at 21:36

2 Answers 2

My feeling is it would be easier to fake it than do it with full physics. If your bugs can be animated, give them an animation of leaping up in the air, rotating, then landing.

You know that sooner or later any physics based method is going to be (heh) buggy. Bug on a slope, object in its way, etc.

share|improve this answer
    
I would really rather avoid animation. This is much closer to a simulation project in this respect. I take your point about scenarios where physics based solutions could fail, though. I really like Mordachai's suggestion of rocking back and forth. Plus, like I said, I'm sure there are arcade racing sims with pseudo-physics methods of self-righting cars that have rolled..? –  Dave Dec 8 '10 at 17:24
2  
Could they just repeatedly try until they get it right? I'm thinking of Click Beetles (see en.wikipedia.org/wiki/Click_beetle) and what they do. They basically keep flipping themselves up in the air until they land upright. It's not terribly graceful but it gets the job done. –  Tim Holt Dec 8 '10 at 18:11
    
Reading about those click beetles made me chuckle. Unfortunately I'm focused on ants/termites here, which afaik can't jump :) –  Dave Dec 8 '10 at 19:52

You should do some kind of rotation impulse.

Probably sideways is the easiest to flip over, so have it either flip over to the right or left, but choose randomly each time.

As for figuring out how much power is needed for the impulse, just test it out. Start it low and keep bumping it till it works correctly. Then figure out the min and max power to flip over correctly. Randomly select one of those when you need to flip.

To make it a bit more realistic, set a small timer between when the object knows its upside down, wait, and when when its time to flip, check if it is still upside down, if so, then flip.

share|improve this answer
    
Problem is, it might not be on its back - could be lying on its side, or even, in rare cases, its head/tail. So problem #1 remains, how to determine the best rotation direction? I figure some cross-producting will be involved, but I'm not sure. Problem #2 - determining the magnitude: you don't think it's feasible to analytically calculate the size of the impulse required, then? Best just to start small and keep increasing until correct orientation is achieved? –  Dave Dec 8 '10 at 19:49
    
No, it is feasible to calculate the impulse required, but that might make the simulation less fun, as bugs would always flip over correctly instead of sometimes messing up. And besides, I am not familiar with the physics engine you use, so wouldn't know where to start with that. –  AttackingHobo Dec 8 '10 at 19:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.