简体   繁体   English

随着时间的推移,libgdx modelinstance平滑地翻译3d对象

[英]libgdx modelinstance translate 3d objects smoothly over time

I'm trying to make a 3d character within a top-down view move in the xy directions when the player uses touchDown input. 当玩家使用touchDown输入时,我试图在自上而下的视图中制作一个3d角色,在xy方向上移动。 So far, I have a cube, using LibGDX ModelInstance, moving whenever the screen is touched, but the cube only moves by a set amount of units; 到目前为止,我有一个立方体,使用LibGDX ModelInstance,每当触摸屏幕时移动,但立方体只移动一定数量的单位; what I really want is for the cube to move by that set amount of units over time for however long the player has the touchDown event called. 我真正想要的是立方体随着时间的推移移动那个设定数量的单位,无论玩家有多长时间都调用了touchDown事件。

I have something like this: 我有这样的事情:

instance.transform.translate(movementRight);

where movementRight is a Vector3(5, 0, 0); 其中movementRight是Vector3(5,0,0); This moves the cube over to the right 5 units once when the player uses the touchDown input. 当玩家使用touchDown输入时,这会将立方体移动到右侧5个单位。 How can I hook this up to update every frame? 如何将其挂钩以更新每一帧? Any help is appreciated. 任何帮助表示赞赏。 Thank you very much! 非常感谢你!

Have a boolean flag that indicates when the cube should be moving right, like this: 有一个布尔标志,指示多维数据集应该向右移动,如下所示:

boolean isMovingRight = false;

Set it to true in the touchDown event, and to false in the touchUp event. 它设置为true下事件,并在触上事件

Then in your render method, do something like this: 然后在你的渲染方法中,做这样的事情:

if(isMovingRight){
    instance.transform.translate(5*delta, 0, 0);
}

This will move the instance 5 units per second, it is very important to do it like this,using delta, so It moves at the same speed independant of FPS . 这将使实例每秒移动5个单位,使用delta这样做是非常重要的,所以它以与FPS无关的相同速度移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM