FPS相机的y轴限制在一定角度玩家到天空向下看的距离(垂直向上和向下)。这是我的代码Vector2mouseLook;Vector2平滑V;公众持股量敏感度=5.0f;公共浮动平滑=2.0f;游戏对象播放器;voidStart(){player=this.transform.parent.gameObject;}//Update每帧调用一次voidUpdate(){varmd=newVector2(Input.GetAxisRaw("MouseX"),Input.GetAxisRaw("MouseY"));md=Vector2.Scale(md,newVector2(灵敏度*平滑,灵敏度*平滑));smoothV.x=Mathf.Lerp(smoothV.x,md.x,1f/平滑);smoothV.y=Mathf.Lerp(smoothV.y,md.y,1f/平滑);mouseLook+=smoothV;transform.localRotation=Quaternion.AngleAxis(-mouseLook.y,Vector3.right);player.transform.localRotation=Quaternion.AngleAxis(mouseLook.x,player.transform.up);你必须使用Mathf.Clamp来实现它。下面是我用来向上/向下和向左/向右旋转相机的内容。您可以将yMaxLimit和yMinLimit变量修改为您想要限制的角度。在x方向上移动时应该没有限制。以上是C#学习教程:FPS相机在y轴限制在一定角度的情况下,共享的所有内容。如果对大家有用,需要详细了解C#学习教程,希望大家多多关注——publicfloatxMoveThreshold=1000.0f;公共浮动yMoveThreshold=1000.0f;公共浮动yMaxLimit=45.0f;公共浮动yMinLimit=-45.0f;浮动yRotCounter=0.0f;浮动xRotCounter=0.0f;/Update每帧调用一次voidUpdate(){xRotCounter+=Input.GetAxis("MouseX")*xMoveThreshold*Time.deltaTime;yRotCounter+=Input.GetAxis("鼠标Y")*yMoveThreshold*Time.deltaTime;yRotCounter=Mathf.Clamp(yRotCounter,yMinLimit,yMaxLimit);//xRotCounter=xRotCounter%360;//可选player.localEulerAngles=newVector3(-yRotCounter,xRotCounter,0);}本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处:
