- Home /
Camera rotates on wrong axis
hello i have a problem with my camera rotating on the wrong axis, it rotates vertical instead of horizontal. the camera is for my rts style game were u can hold the middle mouse button to rotate around at camera position. any help would be appreciated. ty srry for the noob question.
here's my code
var target : Transform; //What to rotate around
var xSpeed = 125.0; //X sensitivity
var ySpeed = 50.0; //Y sensitivity
private var x = 0.0; //Angle of the y rotation?
private var y = 0.0; //Angle of the x rotation?
@script AddComponentMenu("Scripts/Mouse Orbit") //Add to menu
//
function Start ()
{
// Camera Orbit
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
if (rigidbody)
rigidbody.freezeRotation = true;
}
function Update () {
if (Input.GetMouseButton(2))
{
if (target) //There's a target
//Change the angles by the mouse movement
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
//Rotate the camera to those angles
var rotation = Quaternion.Euler(y, x, 0);
transform.rotation = rotation;
}
}
The 1010/010 button formats code to be readable. $$anonymous$$any people won't even read your question unless the code is formatted. I formatted it for you this time.
Answer by robertbu · Mar 24, 2013 at 08:26 PM
For mouse 'X' movement, you want to rotate around the 'Y' axis...for 'Y' movement, the 'X' axis. So reverse your two lines:
y += Input.GetAxis("Mouse X") * xSpeed * 0.02;
x -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
I did not test it. You may also have to change between += and -= in these two statments.
Your answer
Follow this Question
Related Questions
How to make the camera rotate only when right click is held down on the mouse? 1 Answer
Camera Rotation Tips 1 Answer
Camera follows target rotation 3 Answers
Rotate object relative to camera's view 2 Answers
RTS Camera Zoom w/ Rotation 0 Answers