【发布时间】:2021-06-20 09:29:00
【问题描述】:
目前我正在开发一个自上而下的平面游戏,所有运动都是使用 X 和 Z 轴的 2D。我已经根据操纵杆方向计算出旋转,但是,我希望飞机在转弯时在其 Y 轴上旋转,但我找不到最好的方法。
if(movementInput)
{
localRawInput = rawLSInput;
InputDirectionCache = rawLSInput;
}
else
{
localRawInput = InputDirectionCache;
}
targetRotation = Quaternion.LookRotation(localRawInput, Vector3.up);
currentRotation = Quaternion.RotateTowards(currentRotation, targetRotation, currentRotationSpeed);
Vector3 targetRot = targetRotation.eulerAngles;
Vector3 currentRot = currentRotation.eulerAngles;
Vector3 currentDir = currentRotation * transform.forward;
Vector3 targetDir = targetRotation * transform.forward;
这就是我计算所需旋转的方式。应用旋转时,速度仅适用于平面的前方(currentRotation 用于设置旋转) 我正在使用 targetDir 和 currentDir 来计算点积和叉积,以尝试获得一个用于银行的值,但没有运气。
抱歉,如果有点含糊,我不太清楚我要查找的术语
【问题讨论】:
-
什么是localRawInput?输入是浮点数吗?
-
localRawInput 是左摇杆的方向,我缓存了它,所以当没有输入时,它保持原来的方向而不是恢复到 0
-
好的,谢谢。正在寻找答案。
标签: unity3d rotation quaternions dot-product cross-product