unity-夹紧相机的RotateAround功能?

时间:2018-10-21 13:06:19

标签: unity3d

我正在制作一个游戏,玩家在该游戏中绕着行星旋转相机(相机支架的子代)。我需要能够在特定的时间点限制相机的位置(和旋转)。我正在使用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;
 }

1 个答案:

答案 0 :(得分:0)

使用Mathf.clamp()函数。

144282.027 523177.144 0
144281.691 523183.33 0
....