How to rotate a ship using the right analog stick?
I'm creating a racing game in space, and I want the player controlled ship to rotate based on how the player moves the right analog stick. But then I want it to stay at that rotation. Currently the ship moves with the left analog stick, and I've looked at other forum posts to see if I can figure it out, but every time the ship seems to freak out and not rotate on the axis I want it to.
Here's my code for moving the ship:
public Transform ship;
private Vector3 movementVector;
private CharacterController characterController;
private float movementSpeed = 30;
private float gravity = 0.5f;
void Start ()
{
characterController = GetComponent<CharacterController> ();
}
void Update ()
{
movementVector.x = Input.GetAxis ("LeftJoystickX") * movementSpeed;
movementVector.z = Input.GetAxis ("LeftJoystickY") * movementSpeed;
movementVector.y -= gravity * Time.deltaTime;
characterController.Move (movementVector * Time.deltaTime);
}
I want the ship to then rotate only on the y axis, and I don't want it to be able to rise or fall in height.
Your answer
Follow this Question
Related Questions
.rotation doesn't seem to work, can't shoot projectile at mouse coordinates 0 Answers
How do I limit an object to rotate back and forth between 2 angles? 1 Answer
Retaining rotation (preventing rotation snapping) 0 Answers
Copy Rotation in script C# 1 Answer
Limiting gameObjects rotation on Zaxis giving wierd results 1 Answer