Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LIBGDX。有没有办法使矢量2在某一精确点停止具有恒定速度?_Libgdx - Fatal编程技术网

LIBGDX。有没有办法使矢量2在某一精确点停止具有恒定速度?

LIBGDX。有没有办法使矢量2在某一精确点停止具有恒定速度?,libgdx,Libgdx,例如,假设某物以恒定速度移动,位置myposition向下,使用如下方式: myposition.add(velocity.scl(delta)); //position is a Vector2 and velocity is a Vector2 with a negative y value to make the position become more negative. //here is where the texture/sprite gets drawn with myposit

例如,假设某物以恒定速度移动,位置myposition向下,使用如下方式:

myposition.add(velocity.scl(delta));
//position is a Vector2 and velocity is a Vector2 with a negative y value to make the position become more negative.
//here is where the texture/sprite gets drawn with myposition.y.

但是,我想知道是否有一种方法可以使对象在某个点停止,例如当移动对象的y坐标为0(地面)时,而不经过。

您必须自己执行边界交叉检查,并考虑潜在的“重叠”,例如:

velocity.scl(delta);
布尔值willPassZero=myposition.y+velocity.y=0,您还可以使用Math.clamp在y组件穿过0边界后将其向上拉至0

velocity.scl(delta);
boolean willPassZero = myposition.y + velocity.y <= 0;
myposition.add(velocity);
if ( willPassZero )
    myposition.y = 0;