Need some help about MouseLook script and LookAt

Hi,

I was trying to make a camera rotate like while using MouseLook script in the standard assert and I want a player can press a button to snap( LookAt ) a target in screen(First person view) while using MouseLook.

The problem is the MouseLook Script use quatenion to rotate in the following script

        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

        rotationX = ClampAngle(rotationX, minimumX, maximumX);
        rotationY = ClampAngle(rotationY, minimumY, maximumY);

        //Quaternion.
        Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
        Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);

        FPSCamera.transform.localRotation = originalRotation * xQuaternion * yQuaternion;

and I try to use

camera.tranform.LookAt(target);

The thing that happen was my camera lookat target but the MouseLook still use the rotationX and rotationY that sum from before and try to wrap my camera back to where it was before using LookAt.

I know this would be a newbie question but
How can I do this to make it get along together?

Thank you :wink:

hi broccolizz,

the problem may be that you use the inbuilt mouse script …
it could be a better idea to read the Input.Getaxis yourself (its a delta value), and use it with transform.rotate …
the only drawback of this method is that you have to ensure manually that you camera cannot look to high or too low.
(i think thats the reason why they catched the rotation vaules instead of rotate normally)

Hope that helped,
David

I made almost this same exact thing… check it out here and see if it is similar to what you are going for:

note: Press 0 to snap the cam…didn’t put instructions in my webplayer
http://dl.dropbox.com/u/1475775/snapCam.html

For this approach i have the main camera with my built in mouse look script and another camera that is disabled at the exact same position as the main cam… it has my snap to target code and disables main cam when snap cam is active.

//my snap cam to target code

using UnityEngine;

public class SnapCamToTarget : MonoBehaviour
{
    public Transform target = null;
    public GameObject mainCamera = null;

    void Update()
    {
        if (Input.GetKey(KeyCode.Alpha0))
        {
            mainCamera.camera.enabled = false;
            camera.enabled = true;
            transform.LookAt(target);            
        }
        else
        {
            mainCamera.camera.enabled = true;
            camera.enabled = false;
        }

    }
}

Sure, I had do that before and the problem occur as you said if we rotate it too high and rotate right after that the normal rotation would not be back to the originalRotation and this made me realize that why the code save the original rotation and multiply it again and again.
Thank for reply #reculum

Hi, #novashot As looking form your code is when Press 0 down the camera gonna snap and when not , it will swap to the other camera that will use mouselook script that will shot back to the rotation before snap isn’t it?

I am trying to make mouselook itself using the rotation from the snaped rotaion and go along with mouselook without drop back to the last mouselook rotation.

But thank for the idea, If I never figure it out the solution , I think I might have to do this solution too.