using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseLook : MonoBehaviour { public float sensitivity = 1.5f; public float smoothing = 10f; private float xMousePos; private float smoothedMousePos; private float currentLookingPos; private void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } void Update() { GetInput(); ModifyInput(); MovePlayer(); } GetInput() { xMousePos = Input.GetAxisRaw("Mouse X"); } ModifyInput() { xMousePos *= sensitivity * smoothing; smoothedMousePos = Mathf.Lerp(smoothedMousePos, xMousePos, 1f / smoothing); } MovePlayer() { currentLookingPos += smoothedMousePos; transform.localRotation = Quaterion.AngleAxis(currentLookingPos, transform.up); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)