【发布时间】:2017-08-18 22:18:07
【问题描述】:
我正在尝试制作一个统一的 FPP 模式,您可以在其中看到您的实际身体。我创建了一个模型,操纵了一切。我的头会旋转到相机,但我不希望玩家能够围绕他的身体旋转。我已经在 x 轴上夹紧了旋转,但是在围绕 y 轴夹紧时遇到了问题。
void Update () {
currentBodyRotation = body.GetComponent<Transform> ().rotation.eulerAngles.y;
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity;
yawMin = currentBodyRotation - 90f;
yawMax = currentBodyRotation + 90f;
yaw = Mathf.Clamp (yaw, yawMin, yawMax);
pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y);
currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.rotation = Quaternion.Euler (currentRotation);
}
我认为旋转在 0 角和 360 角时有限制。我的代码完美运行,直到身体达到 360 度。当它发生时,虽然我的相机会猛拉,然后从看不见的墙上“弹回”到它来自的一侧。
【问题讨论】:
-
尝试使用this 进行摄像头限制。那应该可以。
-
不起作用。 transform.localEulerAngles 搞砸了我的相机和动画。编辑:我已经修复它但仍然无法正常工作。它停止获取我的部分鼠标输入。
-
认为您在移动相机时有一定的角度限制。该代码适用于 FPS 相机,应附加到没有动画的相机。
-
现在几乎一切正常,但我仍然需要弄清楚如何将相机旋转到适当的位置。每次我启动测试时,我的相机都会围绕 Z 轴旋转 90 度。