我的问题是我的相机在停止鼠标旋转后旋转了一点。
我使用 Cinemachine 虚拟摄像机。角色随镜头转动。
该脚本不是来自我,但它适用于制造商。该脚本来自以下播放列表。
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));
}
}