【发布时间】:2021-12-07 17:49:29
【问题描述】:
我有这段代码,但我无法找到一个合适的解决方案来将 X 轴夹在 2 个角度值之间。这种情况下怎么办?
public class CameraController : MonoBehaviour {
public float cameraSmoothness = 5f;
private Quaternion targetGlobalRotation;
private Quaternion targetLocalRotation = Quaternion.Identity;
private void Start(){
targetGlobalRotation = transform.rotation;
}
private void Update(){
targetGlobalRotation *= Quaternion.Euler(
Vector3.up * Input.GetAxis("Mouse X"));
targetLocalRotation *= Quaternion.Euler(
Vector3.right * -Input.GetAxis("Mouse Y"));
transform.rotation = Quaternion.Lerp(
transform.rotation,
targetGlobalRotation * targetLocalRotation,
cameraSmoothness * Time.deltaTime);
}
}
【问题讨论】:
-
好吧,我找到了一个可能的解决方案,以防它适用于某人:
codeif(transform.rotation.x * 180f > yAxisMin && Input.GetAxis("Mouse Y") > 0 || transform.rotation.x * 180f code -
其中yAxisMin和yAxisMax是y的最小值和最大值
-
但它仍然不能 100% 工作
标签: c# unity3d rotation quaternions clamp