- Home /
Rotate to face the bottom of a unit towards a planet
I would like to have tanks that move around on a planet (a sphere).
Depending on where the unit is, I would like it to always have the bottom of it facing the center of the planet.
To do this I've tried using this:
transform.rotation = Quaternion.LookRotation(planet.position - transform.position);
This will face the object towards the center of the planet but not perpendicular. Also it will change the direction of the Y
axis that the tank fires depending on the position it is on the planet.
How can I set the rotation of the tank so it is always having the bottom of it facing the center of the planet, and keep its current Y
axis rotation?
Y axis is the "up" reference on unity so, how about use lookAt with the current up as reference?
transform.LookAt(planet.position, transform.forward);
and later rotate the data on x axis
transform.Rotate(90.0f, 0.0f, 0.0f, Space.Self);
thats clumsy, but easy to understand, obviously there must be a mathematic-wise solution, and cheap using resources...
Your answer
Follow this Question
Related Questions
Get angle around a specified axis. 1 Answer
How can I rotate a vector direction around an arbitrary axis? 0 Answers
How to Rotate Plane of Cube Around its Center? (Rotate Vectors Around Point/Axis/Direction) 1 Answer
Rotate an object so its up vector matches a sphere 1 Answer
Creating the After Effects Wiggle expression to effect rotation in C# 1 Answer