我正在尝试找到一种在 3D 程序中模拟弹跳的好方法。我尝试这样做的方法如下:我是说,如果position.y < 限制(即-5),则反弹回来。这是代码
if(position.y > LIMITS.y)
velocity.y += Main.GRAVITY/ 1000;
else{
velocity.y = -velocity.y / 1.5f;
System.out.println(true);
}
但是,弹跳有时会起作用,有时会停止得很短,如果有人知道为什么会发生这种情况并可以帮助我改进这一点,我将非常感激。
最佳答案
所以我认为你所说的止损非常短的意思是它弹跳良好然后随机止于底部。这可能是因为对象移动了超过 50% 的距离,它将在低于 y 的 LIMIT 的下一帧中移动。所以对付它的方法就是将y位置重置到它低于之前的位置。
else {
position.y -= velocity.y; // reset to position before going under
velocity.y = -velocity.y / 1.5f; // then adjust the velocity
System.out.println(true);
}
关于java - 在 libgdx java 中模拟弹跳的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34148390/