【发布时间】:2022-01-14 12:15:18
【问题描述】:
我有一个可以在 z 轴和 y 轴上旋转的飞机控制器。当上/下或左/右输入 == 0 时,我希望平面旋转重置(再次变为水平)。
经过一些试验和错误,这可行:
if (Input.GetAxis("Horizontal") == 0.0f && transform.rotation.z != 0f) {
Vector3 tempRotation = new Vector3();
tempRotation.z = 0.0f;
transform.rotation = Quaternion.Euler(tempRotation);
}
但是,它会立即卡入到位。我希望它是一个渐进的轮换。这也会对相机产生负面影响(也包括快照)。
我为每个更新周期等尝试了tempRotation.z -= 0.1f; 之类的东西,但是当它变为 0 时这并没有停止(我不知道为什么):
if (Input.GetAxis("Horizontal") == 0.0f && transform.rotation.z != 0.0f) {
Vector3 tempRotation = transform.rotation.eulerAngles;
tempRotation.z = (float) Math.Round(tempRot.z, 1);
tempRotation.z += 0.1f;
transform.rotation = Quaternion.Euler(tempRotation);
}
有人知道吗?谢谢。
【问题讨论】: