캐릭터가 회전 중이면 카메라가 회전하는 카메라 스크립트가 있습니다. 그러나 카메라를 마우스 포인터로 회전시킬 수도 있습니다. 이 운동은 주어진 각도 (예 : 30 (최대 X))로 제한됩니다. 따라서 마우스로 제어되는 카메라 움직임의 범위는 -30 도와 30도에 해당하는 0과 60 사이 여야합니다.360도 겹치기를 제대로 고정시키는 방법은 무엇입니까?
문자가 360도 회전하면 maxX 값이 360을 넘어 서서 0으로 되돌아 와야합니다. min은 300과 같은 값을 유지할 수 있습니다. 이로 인해 카메라가 "튀어 나오고" 이전 회전.
static function ClampAngle (angle : float, min : float, max : float) : float
{
if (angle < -360.0)
angle += 360.0;
if (angle > 360.0)
angle -= 360.0;
return Mathf.Clamp (angle, min, max);
}
모든 권고 :
var newMaxX = ClampAngle(_target.localEulerAngles.y + maximumX, -360, 360);
var newMinX = ClampAngle(_target.localEulerAngles.y - maximumX, -360, 360);
if(newMinX > newMaxX)
{
var tmp = newMaxX;
newMaxX = newMinX;
newMinX = tmp;
}
if (axes == RotationAxes.MouseXAndY) {
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = ClampAngle (rotationX, newMinX, newMaxX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
cameraTransform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, newMinX, newMaxX);
xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
cameraTransform.localRotation = originalRotation * xQuaternion;
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);
yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
cameraTransform.localRotation = originalRotation * yQuaternion;
}
여기 ClampAngle 기능이있어?