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. Many people won't even read your question unless the code is formatted. I formatted it for you this time.
– robertbu