- Home /
How to make an axis always face an object?
I'm trying to get the bottom of my character to always face the planet beneath it. How could I make a certain axis always point towards the ground. Or is there a better way to go about this. (Planetary Gravity) because nothing else Ive tried has worked on any thing ,but a completely round object. My planet is roundish(kind of an oval) and it's bumpy and such. Any help? Thanks!
If this wouldn't work could I get the shape of the ground below me with a raycast somehow?
Answer by ANGRYSH4RK · May 21, 2014 at 11:22 PM
Here is something quick and easy you can try:
transform.rotation = Quaternion.Lerp(currentRotation, targetRotation, Time.deltaTime * Speed);
Just define targetRotation as the target objects rotation. In your case, the ground.
For the current rotation do something like:
currentRotation = transform.rotation;
And you're done.
Answer by torrente · May 22, 2014 at 02:22 AM
I'd stick with transform.LookAt(planetThing); The specifications are here. Put that in your update and you can guarantee that forward will always point right to the center of the planet. If you need to rotate from there, you would have two options. Either rotate on the line right after this one (a 180) or simply nest the character in another gameObject which will face the planet.
Your answer
Follow this Question
Related Questions
Faux Gravity Prolem? #2 2 Answers
How do i stop rigid bodies jumping? 1 Answer
Changing gravity affecting 'random movement' behaviour script - my NPCs go crazy, what should I do? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
hit.rigidbody.useGravity problem? 1 Answer