- Home /
Gravitational Rotation
I'm fooling around with some body-to-body gravity discussed in this thread:
http://answers.unity3d.com/questions/13639/how-do-i-make-a-small-planet-with-gravitational-pu.html
And I went with this script and it works perfectly fine. http://www.unifycommunity.com/wiki/index.php?title=Gravity
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?
Answer by Bunny83 · Mar 05, 2012 at 10:29 PM
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 ;)
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 could have sworn that there was a drag effect that caused rotation in asymetrical rigidbodies but I see that is not true :(
How would I change that code so that it affects the y-axis ins$$anonymous$$d?
Well, in Unity most methods are optimised for Unity's coordinate system which means: x-axis is right y-axis is up and z-axis is forward. You can parent your projectile to an empty GameObject and compensate the rotation.
Answer by Alec-Slayden · Mar 05, 2012 at 07:56 PM
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.
The gravity is physical, and I've tried the top-heavy approach I think. Could you explain more accurately how I would approach this?
In a gravity field the acceleration depends only on the other mass. Take the classical example of a feather and a hammer fall at the same speed.
yes, but since he implied rotation, I also figured he would be using a drag like air resistance. Which is why dropping a hammer or knife can easily result in the metal hitting the ground first.
Unity's gravity works like real gravity ;)
The problem is the drag. In space there is no drag. If you add drag to your rigidbody, it will turn based on the center of mass. But if you use drag in space most of your objects will fall onto the planet like they had entered the planets atmosphere.
As already said most the time you don't want physically correct behaviour in games. You can change the rules as you need it ;)
it sure does. $$anonymous$$y misinterpretation was in how unity's gravity responded to the 'drag' variable of a rigidbody. I thought it would cause rotation similar to the drag from air resistance, but it does not appear to. Thank you for helping to clarify.
Answer by TurboHermit · Mar 06, 2012 at 08:47 AM
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.
Answer by TurboHermit · Mar 06, 2012 at 08:47 AM
Thanks, what do I need to edit to make it look at the x-axis instead?