我在脚本(Unity)中有一个问题,就是我为汽车控制器做的。当我想旋转汽车的前轮,例如我按下'A‘或'D’车轮将转向左或右(0,45或-45,0),它将立即打开开始旋转(0,0,0),我没有这个问题,当我没有使用Quaternion.Lerp,没有Quaternion.Lerp它工作得很好。任何形式的帮助都会受到欢迎。
//Rotation - WHEELS
CurrentRotation = Horizontal * RotationSpeed * Time.deltaTime;
if (CurrentRotation <= MaximumRotation || CurrentRotation >= -MaximumRotation)
{
Vector3 from_v = new Vector3(Wheels[0].transform.localRotation.x, Wheels[0].transform.localRotation.y, Wheels[0].transform.localRotation.z);
Vector3 to_v = new Vector3(Wheels[1].transform.localRotation.x, CurrentRotation, Wheels[1].transform.localRotation.z);
Quaternion from = Quaternion.Euler(from_v);
Quaternion to = Quaternion.Euler(to_v);
float lerp = 0.5F * (1.0F + Mathf.Sin(Mathf.PI * Time.realtimeSinceStartup * 3f));
Wheels[0].transform.localRotation = Quaternion.Lerp(from, to, lerp);
Wheels[1].transform.localRotation = Quaternion.Lerp(from, to, lerp);
}发布于 2021-04-15 22:24:38
我不完全明白你想要实现什么。是车轮的滚动加上方向盘吗?四元数很棒,但在这里你不需要它们。可以直接获取和设置Euler (主轴)旋转。未测试的代码:
Vector3 rot = Wheels[0].localRotation;
rot.x += speed * Time.deltaTime;
rot.y = (current smoothed steering angle)
Wheels[0].localRotation = rot;
Wheels[1].localRotation = rot;您应该将所有轮子游戏对象的方向设置为指向右侧的X轴和顶部的Y轴。平滑/最大角度取决于输入类型/设备、游戏设置和车速。
如果你支持我的答案那就太好了,这样我就可以在这里写评论了。
致以亲切的问候,克里斯
https://stackoverflow.com/questions/67099775
复制相似问题