创建基于二维旋转的速度公式?
Create a formula for velocity based on rotation in 2d?
所以我有一道数学题。这是作品。
Input:
Rot = Rotation (degrees). This is the rotation of the "player". This is also the yaw.
Vel.X = This is the left/rightward movement that would be happening if it weren't rotated
Vel.Z = Same as last except its up/down movement
Output:
Result.X = This is the actual movement that should be happening along the x axis considering rotation
Result.Z = Same as last
基本上,场景是玩家站在 "Rot" 旋转的平台上。当按下方向键时,速度会相应地添加到 "Vel" 值。但是,如果旋转不是 0,则不会产生正确的结果,因为当玩家旋转时,向左移动变得相对。
能否请您告诉我一个公式,该公式可以找到合适的 x 和 y 移动,从而导致玩家相对于其旋转四处移动?
这个问题大概是游戏编程中最基本的轮换题了
使用您的 Vel.X
和 Vel.Z
值,您可能会想到您希望在 x/z 平面中旋转的矢量(而不是 x/y - 但同样的想法)。无论是速度还是位置,方法都是一样的。通过简单的 google 搜索,我们发现对于 2D 矢量旋转,公式为:
Result.X = Vel.X * cos(Rot) - Vel.Z * sin(Rot);
Result.Z = Vel.X * sin(Rot) + Vel.Z * cos(Rot);
所以我有一道数学题。这是作品。
Input:
Rot = Rotation (degrees). This is the rotation of the "player". This is also the yaw.
Vel.X = This is the left/rightward movement that would be happening if it weren't rotated
Vel.Z = Same as last except its up/down movement
Output:
Result.X = This is the actual movement that should be happening along the x axis considering rotation
Result.Z = Same as last
基本上,场景是玩家站在 "Rot" 旋转的平台上。当按下方向键时,速度会相应地添加到 "Vel" 值。但是,如果旋转不是 0,则不会产生正确的结果,因为当玩家旋转时,向左移动变得相对。
能否请您告诉我一个公式,该公式可以找到合适的 x 和 y 移动,从而导致玩家相对于其旋转四处移动?
这个问题大概是游戏编程中最基本的轮换题了
使用您的 Vel.X
和 Vel.Z
值,您可能会想到您希望在 x/z 平面中旋转的矢量(而不是 x/y - 但同样的想法)。无论是速度还是位置,方法都是一样的。通过简单的 google 搜索,我们发现对于 2D 矢量旋转,公式为:
Result.X = Vel.X * cos(Rot) - Vel.Z * sin(Rot);
Result.Z = Vel.X * sin(Rot) + Vel.Z * cos(Rot);