Hi. I’ve been trying to make a script for a First Person camera, and I’ve looked around but I can’t seem to find anything that someone else has made that I can incorporate as I want. The problem I’m having is that in my script, whenever I move my mouse the rotationX and rotationY seem to keep jumping back to 0 immediately after the value changes (I can see the camera move very quickly before it goes back to 0 rotation). I kind of tried to simplify other examples of FPS scripts I’ve seen, but what could be missing (what is there that shouldn’t be there?) that’s making my variables go back to 0?
var sensitivityX:float = 15f;
var sensitivityY:float = 15f;
var rotationX:float = 0f;
var rotationY:float = 0f;
var originalrotation:Quaternion;
function start ()
{
originalrotation = transform.localrotation;
}
function Update ()
{
rotationX = Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
rotationY = Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);
transform.localRotation = xQuaternion * yQuaternion;
}