统一 - 相机的夹紧旋转功能?



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

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

使用 Mathf.clamp(( 函数。

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

最新更新