我用相机(作为孩子)旋转一个3D对象,用鼠标和键盘旋转一个刚体。我正在使用以下代码片段:
private void Update()
{
float rh = Input.GetAxisRaw("Mouse X");
float rv = Input.GetAxisRaw("Mouse Y");
float rx = Input.GetAxisRaw("Roll");
rotInput = new Vector3(rv, rh, rx);
Thrust(); //Move forward and backward
}
private void FixedUpdate()
{
Moving.MoveInput(rotInput);
}我可以用鼠标移动3D对象(和相机),但当我向左或向右看时,相机会滑动一点对角线。我想用鼠标旋转,就像FPS一样,但要有刚体(不是transform.euler...)。有没有人知道一种解决方案,可以让相机按鼠标的顺序移动(不滑动对角线)?
我将代码更改为:
void moveWithMouse()
{
moveCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), arrowMouseSpeed);
}
void moveCamera(float horizontal, float verticle, float moveSpeed)
{
mouseX = horizontal;
mouseY = -verticle;
rotY += mouseX * moveSpeed;
rotX += -mouseY * moveSpeed;
roll += Input.GetAxis("Roll");
rotInput = new Vector3(rotY, rotX, roll);
Debug.Log("rotInput" + rotInput);
} 但现在它一直在旋转,我停不下来了。我仍然使用ridigbody。有没有一个解决方案,当我停止移动鼠标时,鼠标可以正常工作,摄像头停止旋转?
发布于 2018-09-28 09:17:05
你不需要一卷。这就是相机倾斜的原因。将rotInput = new Vector3(rv, rh, rx);的z设置为0,它应该可以正常工作。
https://stackoverflow.com/questions/52543381
复制相似问题