diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index 44c9d3c..2de5987 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -55,10 +55,7 @@ CollisionResult result; result = PhysicsUtility.checkCollision(player.getObject(), null, object.getObject(), null); if (result != null) { - result.normal.scale(-1); - Vector3d vec = object.getPosition().getVector3d(); - vec.add(result.normal); - object.setPosition(new Position3D(vec)); + objMove(result,object); } } @@ -69,16 +66,17 @@ Vector3d vec1 = object1.getVelocity().getVector3d(); Vector3d vec2 = object2.getVelocity().getVector3d(); if (vec1.length() > vec2.length()) { - result.normal.scale(-1); - Vector3d vec = object1.getPosition().getVector3d(); - vec.add(result.normal); - object1.setPosition(new Position3D(vec)); + objMove(result,object1); }else { - result.normal.scale(-1); - Vector3d vec = object2.getPosition().getVector3d(); - vec.add(result.normal); - object2.setPosition(new Position3D(vec)); + objMove(result,object2); } } } + + private void objMove(CollisionResult result,Object object) { + result.normal.scale(-1); + Vector3d vec = object.getPosition().getVector3d(); + vec.add(result.normal); + object.setPosition(new Position3D(vec)); + } }