如何减慢box2d体的线性或角速度

Sto*_*sdg 6 java velocity box2d libgdx

我有一个圆形动态的身体,模拟一个弹跳球,我将恢复原状设置为2,它只是失去控制,它不会停止上下弹跳.所以我想使用阻尼减慢球的线性或角速度.

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);
Run Code Online (Sandbox Code Playgroud)

当球的线速度达到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);
Run Code Online (Sandbox Code Playgroud)

Net*_*ero 2

这是我用来限制身体速度的常用方法:

if(ball.getLinearVelocity().x >= MAX_VELOCITY)
      ball.setLinearVelocity(MAX_VELOCITY,ball.getLinearVelocity().y)
if(ball.getLinearVelocity().x <= -MAX_VELOCITY)
      ball.setLinearVelocity(-MAX_VELOCITY,ball.getLinearVelocity().y);
if(ball.getLinearVelocity().y >= MAX_VELOCITY)
      ball.setLinearVelocity(ball.getLinearVelocity().x,MAX_VELOCITY)
if(ball.getLinearVelocity().y <= -MAX_VELOCITY)
      ball.setLinearVelocity(ball.getLinearVelocity().x,-MAX_VELOCITY);
Run Code Online (Sandbox Code Playgroud)

请在render()方法中尝试此代码,它将限制您正在制作的球体的速度

祝你好运