美文网首页
Unity实现战场镜头左右上下旋转

Unity实现战场镜头左右上下旋转

作者: 小骄傲999 | 来源:发表于2020-08-11 11:52 被阅读0次

1、左右旋转

float RotationX = Input.GetAxis("Mouse X") * Speed;//Speed=2

float rotatedAngle = camera.transform.localRotation.eulerAngles.y + RotationX ;//旋转角度小于15则设置为15          

if (rotatedAngle < 15)

 {

                camera.transform.RotateAround(player.position, camera.transform.right, RotationX  + (15 - rotatedAngle));

}

else if (rotatedAngle > 85) //旋转角度大于85则设置85            

{

              camera.transform.RotateAround(player.position, camera.transform.right, RotationX  - (rotatedAngle - 85));

 }

else            

{

              camera.transform.RotateAround(player.position, camera.transform.right, RotationX );

}

2、上下旋转

float RotationY = -Input.GetAxis("Mouse Y") * Speed;//speed=2

float RotationY1 = camera.transform.localRotation.eulerAngles.x + RotationY;

        if (RotationY1 > 45 && RotationY > 0)

        {

            camera.RotateAround(Vector3.zero, camera.right, RotationY - (RotationY1 - 45));

        }

        else if (RotationY1 < 10 && RotationY < 0)

        {

            camera.RotateAround(Vector3.zero, camera.right, RotationY + (10 - RotationY1));

        }

        else

        {

            camera.RotateAround(Vector3.zero, camera.right, RotationY);

        }

相关文章

网友评论

      本文标题:Unity实现战场镜头左右上下旋转

      本文链接:https://www.haomeiwen.com/subject/sziedktx.html