Libgdx旋转ModelInstance
我正在开发我的第一个libgdx 3D游戏。 到目前为止,我可以在迷宫般的(硬编码)世界中移动,碰撞检测工作。 我也有一些工作A *寻路的敌人。 我还使用FBX-Conv
来获取.g3db
文件,这是我的第一个(相当难看的)Blender模型。 由于某种原因,模特在地板上而不是站立。 当我将它导出为.fbx
时,我可能有一些错误的设置。 为此我尝试rotate()
他在z-Axis
modelInstance.transform.rotate(Vector3.Z, 90)
rotate()
90
度,在我的Screen
的show()
方法中调用: modelInstance.transform.rotate(Vector3.Z, 90)
,加载Model
并实例化我的ModelInstance
(在给定的位置)。 由于某种原因,它没有旋转。 然后我将rotate
方法放在render(delta)
,认为它现在每个渲染循环旋转90度。 但它反而停滞不前,就像它应该的那样。 好的,但是现在我希望modelInstance
rotate
到它实际看起来的位置,这意味着它应该旋转,这取决于我的enemie
的Vector3 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的帮助解决了这个问题。 问题是:
- 我使用
setToTranslation
将我的Model
移动到给定位置,但是这会重置rotation
- 我想念了
setToRotation(Vector3, Vector3)
方法。
所以解决方法是首先使用setToTranslation
,然后使用setToRotation(Vector3 direction, Vector3 face)
,其中direction
是方向,我的Model
正在查看, face
是face
, face
这个方向,在我的情况下Vector3.X
。
希望它可以帮助别人。