Gravitational Rotation

I’m fooling around with some body-to-body gravity discussed in this thread:

And I went with this script and it works perfectly fine.

Except for, the body that’s affected by the gravity, doesn’t rotate by force alone. I want the top of the object to rotate (target) towards the planet when it’s being pulled by it. I can’t seem to figure out how to do this.

Anyone any suggestions?

Edit: I misinterpreted the way Unity's physical gravity worked (could have sworn I had a top-heavy effect work before using drag to simulate resistance) :(

I suppose I’d say use the SmoothLookAt script included in the assets, and change its target.

If you need something more accurate than the damper of SmoothLookAt, you may want to store the LookAt() rotation towards your gravity, and use Quaternion.Lerp, modified by the strength of the gravity.

Gravity never causes rotation. Gravity always pulls on the center of mass, so an orbiting object won’t rotate due to gravity. On Earth objects rotate due to air-resistance and the relation between the center of mass and the center of drag.

But don’t forget the golden rule in video games / movies:

impression / appeal  >  logic

So it doesn’t have to be realistic. It should look / feel good :wink:

To rotate the object in the direction of movement, you could use LookAt or Quaternion.LookRotation.

transform.rotation = Quaternion.LookRotation(rigidbody.velocity);

With this line the z-axis will always point in the direction of movement.

I tried to center the mass in the top, which it does… I also tried adding drag to the object I want rotated and though it resulted in some funny looking exploits, it still doesn’t amount to the wanted effect. I think I might use the lookAt solution and make it trigger within a radius or something.

Thanks, what do I need to edit to make it look at the x-axis instead?