Turn Rightside Up

How would you script an object so that it automatically turns right side up over a period of time? Imagine a floating object with a weighted base or one of those blow-up punching bags. Basically a force that slowly zeros out one axis of rotation.

Thanks!

Hey,

You can try something like this:
http://gtproductions.net/projects/sandbox/punching_bag.html

Just make your “punching bag” a rigidbody with some drag and angular drag, and gravity affected. Add a hinge joint on the bottom, use the ground or base mesh as the connected body. Then just add a constant force in the Y direction. The stronger the force, the more springy and upright the object will be. With no angular or regular drag, the thing will be like a metronome and swing forever :slight_smile:

Wow- that approach is totally different from what I was trying. It sounds like it should work. I’ll give it a shot. Here is where I’ve gotten so far. It does correct the angle, but it is kind of jerky. This basically turns the object right-side-up but maintains heading. Percent is a variable that adjusts how much influence it has. That’s the idea at least :slight_smile:

var newRot : Quaternion = Quaternion.LookRotation(transform.forward, Vector3.up);		
transform.rotation = Quaternion.Lerp(transform.rotation, newRot, percent);