Fix correction impulse on ball

This commit is contained in:
Matt Low 2018-11-15 22:03:12 +04:00
parent f70dc67878
commit 4fa5841fb2

View File

@ -21,6 +21,7 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
public static final int BLOCKS_FOR_BOOST = 39;
public static final float MINIMUM_ANGLE = MathUtils.PI/16;
public static final float CORRECTION_IMPULSE = 3f;
private float speed;
private boolean isStuck = true;
@ -64,12 +65,13 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
}
Vector2 velocity = body.getLinearVelocity();
body.setLinearVelocity(velocity.nor().scl(speed));
float rad = velocity.angleRad();
if (Math.abs(rad) < MINIMUM_ANGLE || Math.abs(rad) > MathUtils.PI - MINIMUM_ANGLE) {
body.applyLinearImpulse(new Vector2(0, rad > 0? 1 : -1), pos, true);
Vector2 impulse = new Vector2(0, rad > 0? CORRECTION_IMPULSE : -CORRECTION_IMPULSE);
body.applyLinearImpulse(impulse, pos, true);
}
body.setLinearVelocity(velocity.nor().scl(speed));
}
@Override