Mouselook.js don't move smooth, its jittery

Hi, I rewrite the Mouselook.cs into my Mouselook.js. Also I figured out that everything worked fine with my solution:

public var sensitivityX : float = 15;
public var sensitivityY : float = 15;

public var minimumX : float = -360;
public var maximumX : float = 360;

public var minimumY : float = -60;
public var maximumY : float = 60;

private var rotationX : float = 0;
private var rotationY : float = 0;

private var xQuaternion : Quaternion;
private var yQuaternion : Quaternion;

private var originalRotation : Quaternion;

function Start (){
    if (rigidbody) rigidbody.freezeRotation = true;
    originalRotation = transform.localRotation;

function Update(){
    rotationX += Input.GetAxis("Mouse X") * sensitivityX;
    rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    if ((rotationX >= -360) && (rotationX <= 360)){
        rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
    }else if (rotationX < -360){
        rotationX = Mathf.Clamp (rotationX+360, minimumX, maximumX);
        rotationX = Mathf.Clamp (rotationX-360, minimumX, maximumX);

    if ((rotationY >= -360) && (rotationY <= 360)){
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    }else if (rotationY < -360){ 
        rotationY = Mathf.Clamp (rotationY+360, minimumY, maximumY);
        rotationY = Mathf.Clamp (rotationY-360, minimumY, maximumY);
    xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
    yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);

    transform.localRotation = originalRotation * xQuaternion * yQuaternion;


The script is connected to the MainCamera (FirsPersonController is parent > Graphics and Main Camera are children). But after a few tests i figured out that the camera don't move smooth. Everything seems to judder when I move the mouse.

-> I also recognized this with the standard MouseLook.cs. Any ideas what could evoke this?

Hi, I've been playing around trying to write a better mouse look function and came up with this. Delete the standard mouse look script from the first person controller parent object and also from the child camera. Attach the following script to the child camera only. It will control both the camera (for looking up and down) and also the parent object (for rotating left and right). It uses the Quaternion Lerp function to achieve smooth rotation and uses only a few lines of code.

private var xtargetRotation:float=10;
private var ytargetRotation:float=10;
var xSensitivity:float=10;
var ySensitivity:float=10;
var smoothing=2;
var min=-60;
var max=60;

function Update () 

var yAxisMove:float=Input.GetAxis("Mouse Y")*ySensitivity; // how much has the mouse moved?
ytargetRotation+=-yAxisMove; // what is the target angle of rotation
ytargetRotation=ytargetRotation % 360;

var xAxisMove:float=Input.GetAxis("Mouse X")*xSensitivity; // how much has the mouse moved?
xtargetRotation+=xAxisMove; // what is the target angle of rotation
xtargetRotation=xtargetRotation % 360;


Put all of your actual camera movement code into LateUpdate() so that it's locked at being updated every 1 frame

function LateUpdate()
     transform.localRotation = originalRotation * xQuaternion * yQuaternion;

Since yours is in the Update() it's being called many times per frame which is causing it to look jittery.

If the original MouseLook script was also "jittery" (the word you were probably looking for), then it's most likely a problem with your specific machine. I've had no problems in the past with using the MouseLook script and having it lag.

You should check to make sure that your computer isn't running anything in the background that may interfere with Unity, and also check to make sure your computer has enough resources to run Unity smoothly.

For anyone who wants it, I translated this into C# on my way to modifying it for my own game. I hope this is helpful to somebody :slight_smile:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[AddComponentMenu("Camera-Control/Smooth Mouse Look")]
public class SmoothMouseLook : MonoBehaviour 
	public float xSensitivity = 10f;
	public float ySensitivity = 10f;
	public float smoothing = 1f;
	public float min = -60f;
	public float max = 60f;
	float xTargetRotation = 10f;
	float yTargetRotation = 10f;
	void Update ()
		float yAxisMove = Input.GetAxis("Mouse Y")*ySensitivity; //how much has Mouse Y moved?
		yTargetRotation += -yAxisMove; //what is the new target rotation?
		yTargetRotation = yTargetRotation % 360; //get the remainder of targetRotation from 360
		yTargetRotation = Mathf.Clamp (yTargetRotation,min,max);
		float xAxisMove = Input.GetAxis ("Mouse X")*xSensitivity; //how much has Mouse X moved?
		xTargetRotation += xAxisMove; //what is the new target rotation?
		xTargetRotation = xTargetRotation % 360; //get the remainder of targetRotation from 360
		transform.localRotation 	= Quaternion.Lerp (transform.localRotation, Quaternion.Euler(yTargetRotation,0,0), Time.deltaTime*10/smoothing);
		transform.parent.rotation 	= Quaternion.Lerp (transform.parent.rotation, Quaternion.Euler(0,xTargetRotation,0), Time.deltaTime*10/smoothing);