Hi All
I’m trying to get something to work but it is eluding me…
Basically, I want to have a fixed camera that, when the right mouse button is held down, looks around. I can achieve this, however the issue arises with the initial camera rotation. In my script, as soon as I hit the right mouse button, the camera snaps to 0,0,0 rotation, and then allows the user to look around.
My desired workflow is:
- Set camera rotation manually by rotating the camera object in the editor
- Hit play, and then when the right mouse button is held down, allows the view to be rotated smoothly from the initial manual rotation
This script needs to be added to more than one camera, hence the need to be able to set an initial rotation in the editor.
My script is a modified version of the camera fly script from the wiki:
var currentCamera : Camera;
var lookSpeed = 3;
var rotationX;
var rotationY;
function Start ()
{
rotationX = currentCamera.transform.rotation.x;
rotationY = currentCamera.transform.rotation.y;
}
function Update ()
{
if (Input.GetMouseButton(1))
{
rotationX += Input.GetAxis("Mouse X")*lookSpeed;
rotationY += Input.GetAxis("Mouse Y")*lookSpeed;
rotationY = Mathf.Clamp (rotationY, -90, 90);
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
}
}
Can anyone help out with this? I think my issue is that I don’t know how to ‘trap’ the initial manual rotation and then feed it into the rotation calculation.
Thanks a lot!