【问题标题】:Vertical rotation camera Unity [duplicate]Unity垂直旋转相机[重复]
【发布时间】: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);

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    将这些行添加到您的代码中:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 2012-12-28
      相关资源
      最近更新 更多