【发布时间】:2022-01-29 02:29:16
【问题描述】:
如何在统一 3d 中限制相机的垂直旋转。 使用 Mathf.Clamp (xRot, min, max) 不起作用,因为它没有夹紧角度
float xRot=Input.GetAxis("Mouse Y")*lookSens;
cam.transform.Rotate(new Vector3(-xRot,0,0),Space.Self);
【问题讨论】:
如何在统一 3d 中限制相机的垂直旋转。 使用 Mathf.Clamp (xRot, min, max) 不起作用,因为它没有夹紧角度
float xRot=Input.GetAxis("Mouse Y")*lookSens;
cam.transform.Rotate(new Vector3(-xRot,0,0),Space.Self);
【问题讨论】:
将这些行添加到您的代码中:
Vector3 CurrentCameraAngle = cam.transform.eulerAngles;
if (transform.eulerAngles.x > MaxAngle)
cam.transform.eulerAngles = new Vector3(MaxAngle, CurrentCameraAngle.y, CurrentCameraAngle.z);
else if (transform.eulerAngles.x < MinAngle)
cam.transform.eulerAngles = new Vector3(MinAngle,CurrentCameraAngle.y, CurrentCameraAngle.z);
【讨论】: