To change 2 quaternions based on 1 input
Input.GetAxis ("Horizontal"); Quaternion rot = transform.rotation; float z = rot.eulerAngles.z; z -= Input.GetAxis ("Horizontal") * TurnSpeed * Time.deltaTime; rot = Quaternion.Euler (0, 0, z); transform.rotation = rot; Vector3 pos = transform.position; Vector3 velocity = new Vector3 (0, Input.GetAxis("Vertical") * Speed * Time.deltaTime, 0); pos += rot * velocity; if (pos.y + shipBoundaryRadius > Camera.main.orthographicSize) { pos.y = Camera.main.orthographicSize - shipBoundaryRadius; } if (pos.y - shipBoundaryRadius < -Camera.main.orthographicSize) { pos.y = -Camera.main.orthographicSize + shipBoundaryRadius; } float screenRatio = (float)Screen.width / (float)Screen.height; float widthOrtho = Camera.main.orthographicSize * screenRatio; if (pos.x + shipBoundaryRadius > widthOrtho) { pos.x = widthOrtho - shipBoundaryRadius; } if (pos.x - shipBoundaryRadius < -widthOrtho) { pos.x = -widthOrtho + shipBoundaryRadius; } transform.position = pos;
Ok, Ive been all over the net with this. Please help. Im doing a 2D top down space shooter. The spaceship can fly all over the screen within the cameras borders. And it flies to where its nose is pointing. I can set up the code for rotating the ship so it turns on the Z axis and forward and backwards works fine. But I also want the ship to "bank" when it is turning, thus rotating on its Y axis. Somehow I cant get this to work!? The ship is a 3D object. Code in Update:
Your answer

Follow this Question
Related Questions
Quaternion.Euler to rotate camera with input system V2's snaps camera to 0 0 Answers
Help with suns rotation 0 Answers
Relative rotation on a custom axis? 0 Answers
How do I limit the roll of a game object? 0 Answers
Quaternion/World Local rotation problem 0 Answers