【发布时间】:2016-01-04 10:59:00
【问题描述】:
我有一个模拟弹跳球的圆形动态体,我将恢复原状设置为 2,它只是失控到它不会停止上下弹跳的程度。所以我想使用 Damping 来减慢球的线速度或角速度。
if(ball.getLinearVelocity().x >= 80 || ball.getLinearVelocity().y >= 80)
ball.setLinearDamping(50)
else if(ball.getLinearVelocity().x <= -80 || ball.getLinearVelocity().y <=-80)
ball.setLinearDamping(50);
当球的线速度达到 80 或以上时,我将其线性阻尼设置为 50,然后它就会进入超慢动作。谁能解释一下阻尼的工作原理以及如何正确使用.setLinearDamping()方法,谢谢。
编辑
这就是我所做的,如果线速度超过了我需要的值,它会将球的线性阻尼设置为 20,如果不总是将其设置为 0.5f。这会产生并影响重力不断和瞬间变化。但是@minos23 的答案是正确的,因为它更自然地模拟了球,您只需要设置您需要的 MAX_VELOCITY。
if(ball.getLinearVelocity().y >= 30 || ball.getLinearVelocity().y <= -30)
ball.setLinearDamping(20);
else if(ball.getLinearVelocity().x >= 30 || ball.getLinearVelocity().x <= -30)
ball.setLinearDamping(20);
else
ball.setLinearDamping(0.5f);
【问题讨论】:
-
请告诉我们提供的解决方案是否对您有用,如果有任何问题发表评论,祝您好运
标签: java libgdx box2d velocity