From c98a16dae96b4c0b112eeaf2f070ae950e411816 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Sat, 16 May 2015 21:50:19 +0300 Subject: [PATCH] Fixed a precision bug when handling big physics objects & removed 2 random platforms from TestLevel. --- .../saltosion/gladiator/level/TestLevel.java | 22 ------------------- .../gladiator/systems/PhysicsSystem.java | 13 ++++++----- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/core/src/com/saltosion/gladiator/level/TestLevel.java b/core/src/com/saltosion/gladiator/level/TestLevel.java index 3047013..873e8bd 100644 --- a/core/src/com/saltosion/gladiator/level/TestLevel.java +++ b/core/src/com/saltosion/gladiator/level/TestLevel.java @@ -30,29 +30,7 @@ public class TestLevel implements Level { physics.getPosition().set(new Vector2(0, -4)); ground.add(physics); - Sprite wallSprite = SpriteLoader.loadSprite(Name.WALLIMG); - - Entity wall0 = new Entity(); - CRenderedObject wall0RenderedObject = new CRenderedObject(wallSprite); - CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false) - .setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE, - wallSprite.getRegionHeight() * Global.SPRITE_SCALE); - wall0Physics.getPosition().set(new Vector2(6, 0)); - wall0.add(wall0RenderedObject); - wall0.add(wall0Physics); - - Entity wall1 = new Entity(); - CRenderedObject wall1RenderedObject = new CRenderedObject(wallSprite); - CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false) - .setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE, - wallSprite.getRegionHeight() * Global.SPRITE_SCALE); - wall1Physics.getPosition().set(new Vector2(-6, 0)); - wall1.add(wall1RenderedObject); - wall1.add(wall1Physics); - AppUtil.engine.addEntity(ground); - AppUtil.engine.addEntity(wall0); - AppUtil.engine.addEntity(wall1); } } diff --git a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java index 85a7e1f..e89a5d4 100644 --- a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java +++ b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java @@ -9,10 +9,11 @@ import com.badlogic.ashley.utils.ImmutableArray; import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.util.Direction; +import com.saltosion.gladiator.util.Log; public class PhysicsSystem extends EntitySystem { - private static final float MAX_VEL = 1.75f, COLLISION_PRECISION = 18f, UPDATES_PER_SECOND = 120f; + private static final float MAX_VEL = 1.75f, COLLISION_PRECISION = 12f, UPDATES_PER_SECOND = 120f; private static final ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); private static final ComponentMapper cm = ComponentMapper.getFor(CCombat.class); @@ -98,8 +99,10 @@ public class PhysicsSystem extends EntitySystem { } boolean collidedAlready = false; + float precisionX = COLLISION_PRECISION * (cp0.getSize().x > cp1.getSize().x ? cp0.getSize().x : cp1.getSize().x); + float precisionY = COLLISION_PRECISION * (cp0.getSize().y > cp1.getSize().y ? cp0.getSize().y : cp1.getSize().y); - if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.getSize().x + cp1.getSize().x) / COLLISION_PRECISION) { + if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.getSize().x + cp1.getSize().x) / precisionX) { // cp0's left side is colliding with cp1's right side if (!cp0.isGhost() && !cp1.isGhost()) { if (cp0.getVelocity().x < 0) { @@ -114,7 +117,7 @@ public class PhysicsSystem extends EntitySystem { } collidedAlready = true; } - if (x01 > x10 && Math.abs(x01 - x10) < (cp0.getSize().x + cp1.getSize().x) / COLLISION_PRECISION) { + if (x01 > x10 && Math.abs(x01 - x10) < (cp0.getSize().x + cp1.getSize().x) / precisionX) { // cp0's right side is colliding with cp1's left side if (!cp0.isGhost() && !cp1.isGhost()) { if (cp0.getVelocity().x > 0) { @@ -129,7 +132,7 @@ public class PhysicsSystem extends EntitySystem { } collidedAlready = true; } - if (y00 <= y11 && Math.abs(y00 - y11) < (cp0.getSize().y + cp1.getSize().y) / COLLISION_PRECISION) { + if (y00 <= y11 && Math.abs(y00 - y11) < (cp0.getSize().y + cp1.getSize().y) / precisionY) { // cp0's bottom side is colliding with cp1's top side if (!cp0.isGhost() && !cp1.isGhost()) { if (cp0.getVelocity().y < 0) { @@ -145,7 +148,7 @@ public class PhysicsSystem extends EntitySystem { } collidedAlready = true; } - if (y01 > y10 && Math.abs(y01 - y10) < (cp0.getSize().y + cp1.getSize().y) / COLLISION_PRECISION) { + if (y01 > y10 && Math.abs(y01 - y10) < (cp0.getSize().y + cp1.getSize().y) / precisionY) { // cp0's top side is colliding with cp1's bottom side if (!cp0.isGhost() && !cp1.isGhost()) { if (cp0.getVelocity().y > 0) {