I am new to game development , I am following a book Unity in action by Manning . This is the code snippet used to rotate a game object (from the book):
public RotationAxes axes = RotationAxes.MouseXandY;
public float sensitivityHorizontal = 9.0f;
public float sensitivityVert = 9.0f;
private float rotationX = 0;
public float minimumVert = -45.0f;
public float maximumVert = 45.0f;
// Update is called once per frame
void Update () {
float input = Input.GetAxis ("Mouse X");
//Vertical Rotation
if (axes == RotationAxes.MouseY) {
rotationX-= Input.GetAxis ("Mouse Y") * sensitivityVert;
rotationX = Mathf.Clamp (rotationX, minimumVert, maximumVert);
float rotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3 (rotationX, rotationY, 0);
}
}
This code actually works but the other way around i.e when my move my mouse upwards the object rotates down and up when I move down . I figured out that it was rotationX-= Input.GetAxis ("Mouse Y") * sensitivityVert; this that was causing the problem so I change it to rotationX+= Input.GetAxis ("Mouse Y") * sensitivityVert; and now it rotates really strangely ! I have made sure that it only rotates in vertical axis but it's rotating in all the directions i.e even in horizontal and z axis. Can somebody please tell me where I am going wrong? ThankYou