Hey guys, thought I would share this super simple but very effective “smooth look” script for your First Person Shooter. It is a way simpler and improved script with better performance than what I could find in the wiki. Hope this can help someone: Just replace your current MouseLook c# scripts on the Unity FPS with this one and tweek:
Remember you need this script 1) on your Main Camera (Axes set to MouseX) and 2)on the root First PersonController (Axes set to mouseY):
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX;
public float sensitivityY;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
public static float cur_x;
public static float last_x;
public static float cur_y;
public static float last_y;
void Update ()
{
if (axes == RotationAxes.MouseX)
{
cur_x = Mathf.Lerp(last_x, Input.GetAxis("Mouse X"), sensitivityX);
last_x = cur_x;
}
else
{
cur_y = Mathf.Lerp(last_y, Input.GetAxis("Mouse Y"), sensitivityY);
last_y = cur_y;
transform.localEulerAngles += new Vector3(-cur_y, cur_x, 0);
}
}
void Start ()
{
sensitivityX = 0.15f;
sensitivityY = 0.15f;
if (rigidbody)
rigidbody.freezeRotation = true;
}
}
Please pop me a msg if you use it in your game! Cheers!