diff --git a/src/engine/CollisionEngine/CollisionManager.java b/src/engine/CollisionEngine/CollisionManager.java index c5d58315..b86ee1aa 100644 --- a/src/engine/CollisionEngine/CollisionManager.java +++ b/src/engine/CollisionEngine/CollisionManager.java @@ -5,9 +5,14 @@ import engine.objects.Building; import java.awt.*; import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; public class CollisionManager { public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){ + + if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2())) + return false; + for (Mesh mesh : building.buildingMeshes) if(mesh.MeshCollides(travelLine,charHeight,charY)) return true; diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index 67a063ca..7edbc215 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -49,11 +49,13 @@ public class RegionCmd extends AbstractDevCmd { } if(building != null){ for (Mesh mesh : building.buildingMeshes){ - if(mesh.boundsRect.contains(pc.loc.x,pc.loc.z)) + if(mesh.boundsRect.contains(pc.loc.x,pc.loc.z)) { this.throwbackInfo(pc, "Inside A Mesh's Bounds"); + return; + } } } - + this.throwbackInfo(pc, "Outside All Mesh Bounds"); } @Override diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 318ae411..0e176ed0 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -1046,6 +1046,13 @@ public enum BuildingManager { } building.buildingMeshes.add(generatedMesh); } + Rectangle2D.Float buildingBound = new Rectangle2D.Float(); + float xLoc = building.loc.x - building.getBounds().getHalfExtents().x; + float zLoc = building.loc.z - building.getBounds().getHalfExtents().y; + float width = building.getBounds().getHalfExtents().x * 2; + float height = building.getBounds().getHalfExtents().y * 2; + buildingBound.setRect(xLoc,zLoc,width,height); + building.buildingRect = buildingBound; } catch(Exception e){ Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID); diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index f8220fb9..97ce3cb3 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -36,6 +36,7 @@ import engine.net.client.msg.UpdateObjectMsg; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import java.awt.geom.Rectangle2D; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; @@ -102,6 +103,7 @@ public class Building extends AbstractWorldObject { private ArrayList children = null; public ArrayList buildingMeshes; + public Rectangle2D.Float buildingRect; /** * ResultSet Constructor