- Home /
Rotate Around Planet with Spaceship Face Set on Path
I want to rotate a spaceship around the planet with spaceship not looking towards planet but on it's moving path.
I have created a rough image to explain my point:
I have this code through that I can able to rotate around my spaceship to the planet:
transform.RotateAround(GameController.Instance.planetsList[0].transform.position, Vector3.forward, rotationSpeed * Time.deltaTime);
But still, my spaceship looking towards the planet that I want to stop and look at towards it's circular path.
Please give me some suggestions to achieve this.
Answer by ZoeDreams · Nov 10, 2020 at 03:57 AM
Transform.RotateAround() translates the cartesian position of the actual mesh. Where as Transform.localRotation property will rotate the mesh around its center. Transform.rotate will rotate around the world space.
https://docs.unity3d.com/ScriptReference/Transform-localRotation.html
You will need to call Quaternion.Euler() to determine the rotation angle around the center point.
https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html
Euler function takes in the angle you wish to rotate which in your case would be rotationSpeed * Time.delta.
transform.localRotation = Quaternion.Euler(0f, rotationSpeed * Time.deltaTime, 0f);
some assembly required you might need to calculate the rotation angle separate before creating the Euler transform.
Your answer
![](https://koobas.hobune.stream/wayback/20220612225438im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Resetting transform's original position and rotation after using transform.rotateAround 1 Answer
Rotating an object towards target on a single axis 2 Answers
Orbit around orbiting object (transform.RotateAround) 1 Answer
How to rotate an object around a screen point (mousePosition)? 1 Answer
RotateAround Limitations 2 Answers