Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created September 11, 2014 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/7ba60e3df8ffd1ec58f5 to your computer and use it in GitHub Desktop.
Save olegchir/7ba60e3df8ffd1ec58f5 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class MouseLookScript : MonoBehaviour {
[HideInInspector]
public float xRotation;
[HideInInspector]
public float yRotation;
public float lookSensitivity = 5;
[HideInInspector]
public float currXRotation;
[HideInInspector]
public float currYRotation;
[HideInInspector]
public float xRotationVelocity;
[HideInInspector]
public float yRotationVelocity;
public float smoothDampTime = 0.1f;
// Update is called once per frame
void Update () {
xRotation -= Input.GetAxis ("Mouse Y") * lookSensitivity;
yRotation += Input.GetAxis ("Mouse X") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -90, 90);
currXRotation = Mathf.SmoothDamp(currXRotation, xRotation, ref xRotationVelocity, smoothDampTime);
currYRotation = Mathf.SmoothDamp(currYRotation, yRotation, ref yRotationVelocity, smoothDampTime);
transform.rotation = Quaternion.Euler(currXRotation, currYRotation, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment