- Home /
Move a ship around a planet and rotate ship on Y axis
So I need that a ship move around the surface of a planet at a fixed height. And also rotate on Y axis following the mouse. The camera is 3rd person and follows the ship movement, but don`t rotate on Y axis with the ship. My script does both things but when I start to move the ship, it starts to rotate on X and Z axis. I tried to use RigidBody constraits and it didn`t worked. This is my setup: Planet centered at (0,0,0) GameObject centered at (0,0,0) GameObject(1) same position as the ship. I have a script associated to GameObject for movement:
if (Input.GetKey(KeyCode.UpArrow))
transform.Rotate(new Vector3(2, 0, 0));
if (Input.GetKey(KeyCode.DownArrow))
transform.Rotate(new Vector3(-2, 0, 0));
if (Input.GetKey(KeyCode.RightArrow))
transform.Rotate(new Vector3(0, 0, -2));
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(new Vector3(0, 0, 2));
And a script associated to the ship:
Answer by matheusmr · Oct 23, 2017 at 08:21 PM
The problem was in Quaternion.LookRotation, I was specifing only the first parameter. The fix was to specify the second parameter too. 'upwards' "The vector that defines in which direction up is." by transform.up so the movement is relative to the ship.
Your answer
Follow this Question
Related Questions
How to rotate a character facing direction of movement like sonic the hedgehog 2 Answers
How can I move an object to click point in 2D? 0 Answers
Rotation animation? 3 Answers
Movement along X and Z axis... 2 Answers
how do i rotate and movement together 0 Answers