diff --git a/src/engine/CollisionEngine/CollisionManager.java b/src/engine/CollisionEngine/CollisionManager.java index 9ec8c50c..5777bc23 100644 --- a/src/engine/CollisionEngine/CollisionManager.java +++ b/src/engine/CollisionEngine/CollisionManager.java @@ -1,5 +1,6 @@ package engine.CollisionEngine; +import engine.math.Vector3f; import engine.objects.Building; import java.awt.*; @@ -8,9 +9,9 @@ import java.awt.geom.Line2D; public class CollisionManager { public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight){ Rectangle.Float boundsRect = new Rectangle.Float(); - float rectCenterX = building.loc.x + building.getBounds().getHalfExtents().x; - float rectCenterZ = building.loc.z + building.getBounds().getHalfExtents().y; - boundsRect.setRect(rectCenterX, rectCenterZ, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); + Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y); + + boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); if(travelLine.intersects(boundsRect)){ //collided with building for(Mesh mesh : building.buildingMeshes) { diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index 3438855a..82afdb26 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -22,7 +22,7 @@ public class Mesh { public boolean MeshCollides(Line2D line, float charHeight){ //movement path does not intersect this mesh - if(!this.BoundsCollides(line)) + if(line.intersects(boundsRect) == false) return false; //character moving is higher than the max Y of this mesh diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 75698bf5..630a8222 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -935,7 +935,7 @@ public class dbBuildingHandler extends dbHandlerBase { float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]); - Vector2f topLeft = new Vector2f(centerX - refX,centerZ - refZ); + Vector2f topLeft = new Vector2f(centerX - refX,centerZ + refZ); float width = Math.abs(endX-refX); float height = Math.abs(endZ-refZ); Rectangle2D boundRect = new Rectangle2D.Float();