I have the problem that my camera rotates back a little after a rotation after stopping the mouse.
I use a Cinemachine virtual camera. The character turns with the camera.
The script did not come from me but it works for the maker. The script comes from the following playlist.
https://www.youtube.com/watch?v=CS7MudfyDzM&list=PLyBYG1JGBcd1E4CigRSDE9YdH8syiDY6-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterAiming : MonoBehaviour
{
public float turnSpeed;
Camera mainCamera;
public Transform cameraLookAt;
public Cinemachine.AxisState xAxis;
public Cinemachine.AxisState yAxis;
// Start is called before the first frame update
void Start()
{
mainCamera = Camera.main;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void FixedUpdate()
{
xAxis.Update(Time.fixedDeltaTime);
yAxis.Update(Time.fixedDeltaTime);
cameraLookAt.eulerAngles = new Vector3(yAxis.Value, xAxis.Value, 0);
float yawCamera = mainCamera.transform.rotation.eulerAngles.y;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, yawCamera, 0), turnSpeed * Time.fixedDeltaTime);
Debug.Log(Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, yawCamera, 0), turnSpeed * Time.fixedDeltaTime));
}
}