- Home /
Rotating a camera when RMB is held down.
This is the code that I have so far (for a helicopter game).
var starty : float;
var startx : float;
var startz : float;
if(Input.GetKeyDown("mouse 1")){
starty = gameObject.transform.localRotation.y;
startx = gameObject.transform.localRotation.x;
startz = gameObject.transform.localRotation.z;
}
if(Input.GetKey("mouse 1")){
Screen.lockCursor = true;
gameObject.transform.rotation.y = gameObject.transform.rotation.y -(Input.GetAxis("Mouse X")/40);
}
if(Input.GetKeyUp("mouse 1")){
gameObject.transform.localRotation.y = starty;
gameObject.transform.localRotation.x = startx;
gameObject.transform.localRotation.z = startz;
}
It just doesnt seem to return the camera to the same position as it was when RMB was pressed, just some random position that is a few pixels away. So my question is, can anyone see what is wrong? :S
is this script directly on the camera, or the parent of the camera? There is no modification to transform.position here, so the only way would be if the camera is not at (0,0,0) to the parent object (that I can imagine what is happening here). Do you move the camera anywhere while the R$$anonymous$$B is pressed?
the camera is added to a helocopter cockpit model that i have, when you hold the button, i wish for the player to be able to "look around" as it were... The camera is inside a parent object (the helicopter) to make sure that it stays inside the cockpit,