Libgdx旋转ModelInstance

我正在开发我的第一个libgdx 3D游戏。 到目前为止,我可以在迷宫般的(硬编码)世界中移动,碰撞检测工作。 我也有一些工作A *寻路的敌人。 我还使用FBX-Conv来获取.g3db文件,这是我的第一个(相当难看的)Blender模型。 由于某种原因,模特在地板上而不是站立。 当我将它导出为.fbx时,我可能有一些错误的设置。 为此我尝试rotate()他在z-Axis modelInstance.transform.rotate(Vector3.Z, 90) rotate() 90度,在我的Screenshow()方法中调用: modelInstance.transform.rotate(Vector3.Z, 90) ,加载Model并实例化我的ModelInstance (在给定的位置)。 由于某种原因,它没有旋转。 然后我将rotate方法放在render(delta) ,认为它现在每个渲染循环旋转90度。 但它反而停滞不前,就像它应该的那样。 好的,但是现在我希望modelInstance rotate到它实际看起来的位置,这意味着它应该旋转,这取决于我的enemieVector3 direction 。 我已经准备好使用modelInstance.transform.setTotranslation(enemie.getPosition())来完善自己的位置。 所以我想我也可以使用modelInstance.transform.setToRotation(Vector3 v1, Vector3 vs) ,其中v1 = enemie.getPosition()v2 = enemie.getPosition().add(enemie.getDirection) 。 请注意, position Vector不会直接使用,因为它会在add()方法中更改其值。 这样做,我不再看到对象,这意味着它的位置也是错误的。

为什么会这样? 我如何通过使用direction向量来旋转我的modelInstance

非常感谢。

我用@Xoppas的帮助解决了这个问题。 问题是:

  1. 我使用setToTranslation将我的Model移动到给定位置,但是这会重置rotation
  2. 我想念了setToRotation(Vector3, Vector3)方法。

所以解决方法是首先使用setToTranslation ,然后使用setToRotation(Vector3 direction, Vector3 face) ,其中direction是方向,我的Model正在查看, facefaceface这个方向,在我的情况下Vector3.X

希望它可以帮助别人。