【问题标题】:Unity - clamping RotateAround function for camera?Unity - 夹紧相机的RotateAround功能?
【发布时间】:2018-10-21 13:06:18
【问题描述】:

我正在制作一个游戏,其中玩家围绕行星旋转相机(相机支架的孩子)。我需要能够在某些时间点夹住相机的位置(和旋转)。我正在使用 RotateAround 函数,我想知道是否有人可以帮助我将其夹住?我的代码如下:

private void RotateCamera(Vector3 dragStartPosition, Vector3 dragEndPosition)
 {

     //normalised for odd edges
     dragEndPosition = dragEndPosition.normalized *planetRadius;
     dragStartPosition = dragStartPosition.normalized * planetRadius;

     // Cross Product
     Vector3 cross = Vector3.Cross(dragEndPosition, dragStartPosition);

     // Angle for rotation
     float angle = Vector3.SignedAngle(dragEndPosition, dragStartPosition, cross);

     //Causes Rotation of angle around the vector from Cross product
     holderTransform.RotateAround(planet.transform.position , cross, angle);

     EventHandler.instance.AddHiddenEvent(EventHandler.EventType.panCamera);
 }


 private static Vector3? GetMouseHit()
 {
     RaycastHit hit;
     int layer_mask = LayerMask.GetMask("Planet"); //raycasting on the planet
     if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, layer_mask))
     {
         return hit.point;
     }
     return null;
 }

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    使用 Mathf.clamp() 函数。

    public static float Clamp(float value, float min, float max);
    

    【讨论】:

      猜你喜欢
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多