From 4fa5841fb25b5f0a845e7fa9f335a481929aad4f Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 15 Nov 2018 22:03:12 +0400 Subject: [PATCH] Fix correction impulse on ball --- core/src/com/me/brickbuster/entity/Ball.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 5a51294..4a89b6a 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -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