Hello,
I am new at Unity and after watching multiple tutorials, I created this script to make a smooth FPS-Cam:
public class CamMovement : MonoBehaviour
{
private float MouseSensivity;
public float MaxY;
public float MinY;
public Transform Bodytrans;
float xRotation;
float yRotation;
public Slider SensivitySlider;
public float SpinSpeed;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
SensivitySlider.value = 100;
}
void SetSliderValues(){...}
void CursorLock(){...}
void CamRotate()
{
float mouseX = Input.GetAxis("Mouse X") * MouseSensivity *
Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * MouseSensivity *
Time.deltaTime;
xRotation -= mouseY;
yRotation += mouseX;
xRotation = Mathf.Clamp(xRotation, MinY, MaxY);
Quaternion RotationY = Quaternion.Euler(xRotation,0, 0);
Quaternion RotationX = Quaternion.Euler(0, yRotation, 0);
transform.localRotation = Quaternion.Lerp(transform.localRotation, RotationY, SpinSpeed * Time.deltaTime);
Bodytrans.rotation = Quaternion.Lerp(Bodytrans.rotation, RotationX, SpinSpeed * Time.deltaTime);
}
void Update()
{
CamRotate();
CursorLock();
SetSliderValues();
}
}
The Problem: The Cam keeps bouncing on the X-Axis when moving at fast speed.
Example: I move the Cam to the right with high MouseSensivity. The mouse now bounces back to the left. This only occurs at high speed.
I have tried using Bodytrans.Rotate() instead of Quaternion.Lerp() first; This does remove the bouncing, but it also causes a weird stuttering, like the Camera is skipping frames. If Bodytrans.Rotate() is the right choice, how do you remove the stuttering?
Thanks in advance!