I am making an FPS game, and I want the camera to be smooth, like this (with adjustable smoothness):
here’s my code (you can use it to adjust it if you like:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SmoothMouseLook : MonoBehaviour
{
//Floats
public float sensitivity = 100f;
float xRotation = 0f;
//Vetors, Transforms, and GameObjects
public Transform playerBody;
void Start()
{
//Locks Cursor
Cursor.lockState = CursorLockMode.Locked;
}
void LateUpdate()
{
//Get's Input from da mouse
float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
//Clamping
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
//Rotating
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}