1 year ago
#360271
cutaepie
Why is my camera rotating in Z axis when it should be X and Y? Unity
So I'm creating a tower defence game and I want to make the camera rotate left and right, up and down around the map by dragging right click (I want it to be like the "real chess 3D" app on mobile). I am a beginner at C#/Unity.
First I made it rotate left and right and it worked fine. But I had no idea how to also make it move up and down, so I just did trial and error and it kind of works. But the camera also rotates in the z axis slightly for some reason, when it should only be x and y axis. This is the code:
if(Input.GetMouseButtonDown(1))
{
Debug.Log("Right clicked!");
rotateStartPosition = Input.mousePosition;
}
if(Input.GetMouseButton(1))
{
Debug.Log("Holding right click!");
rotateCurrentPosition = Input.mousePosition;
Vector3 difference = rotateStartPosition - rotateCurrentPosition;
rotateStartPosition = rotateCurrentPosition;
newUpRotation *= Quaternion.Euler(Vector3.up * (-difference.x / 5f));
newRightRotation *= Quaternion.Euler(Vector3.right * (difference.y / 5f));
}
transform.rotation = Quaternion.Lerp(transform.rotation, newUpRotation * newRightRotation, Time.deltaTime * movementTime);
c#
unity-game-engine
quaternions
0 Answers
Your Answer