I have a dynamic circle-shaped body that mimics a bouncing ball, I set the restitution to 2, and it just gets out of control until it stops jumping up and down. So I want to slow down linear speed or angular speed with 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);
When the linear speed of the ball reaches 80 or higher, I set its linear damping to 50, then it just goes in super slow motion. Can someone please explain to me how Damping works and how to use the .setLinearDamping() method .setLinearDamping() , thanks.
EDIT
This is what I did if the linear speed exceeded what I needed, sets the ball by linear damping to 20, if it does not always set it to 0.5f. This creates and leads to the fact that gravity changes constantly and instantly. However, @ minos23's answer is correct, because it mimics the ball more naturally, you just need to set MAX_VELOCITY what you need.
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);
source share