diff --git a/src/engine/CollisionEngine/CollisionManager.java b/src/engine/CollisionEngine/CollisionManager.java index 5777bc23..6e1733c0 100644 --- a/src/engine/CollisionEngine/CollisionManager.java +++ b/src/engine/CollisionEngine/CollisionManager.java @@ -7,7 +7,7 @@ import java.awt.*; import java.awt.geom.Line2D; public class CollisionManager { - public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight){ + public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){ Rectangle.Float boundsRect = new Rectangle.Float(); Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y); @@ -15,7 +15,7 @@ public class CollisionManager { if(travelLine.intersects(boundsRect)){ //collided with building for(Mesh mesh : building.buildingMeshes) { - if (mesh.MeshCollides(travelLine,charHeight)) { + if (mesh.MeshCollides(travelLine,charHeight, charY)) { //ChatManager.chatSystemInfo(pc, "Collision Detected"); //MovementManager.movement(msg, pc); return true; diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index 82afdb26..98d6f5a3 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -9,7 +9,8 @@ public class Mesh { public ArrayList triangles; public ArrayList BoundingLines; public Rectangle2D boundsRect; - public float meshHeight; + public float maxY; + public float minY; public boolean BoundsCollides(Line2D line){ for(Line2D side : BoundingLines) @@ -19,14 +20,15 @@ public class Mesh { return false; } - public boolean MeshCollides(Line2D line, float charHeight){ + public boolean MeshCollides(Line2D line, float charHeight, float charY){ //movement path does not intersect this mesh - if(line.intersects(boundsRect) == false) + //if(line.intersects(boundsRect) == false) + if(!this.BoundsCollides(line)) return false; //character moving is higher than the max Y of this mesh - if(charHeight > this.meshHeight) + if(charY > this.maxY && charHeight + charY < this.minY) return false; for(Triangle tri : triangles) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index e0162ab9..184e5cae 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -923,7 +923,8 @@ public class dbBuildingHandler extends dbHandlerBase { while (rs.next()) { if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){ - BuildingManager.mesh_heights.put(rs.getInt("meshID"),rs.getFloat("maxY")); + Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY")); + BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights); } } diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index 6cb556a3..a3d284f5 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -50,7 +50,7 @@ public class RegionCmd extends AbstractDevCmd { if(building != null){ for(Mesh mesh : building.buildingMeshes){ if(mesh.boundsRect.contains(new Point2D.Float(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z))){ - if(((AbstractCharacter) target).loc.y < mesh.meshHeight) { + if(((AbstractCharacter) target).loc.y < mesh.maxY) { this.throwbackInfo(pc, "Inside Mesh Bounds"); return; } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index af98a462..af749ba8 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -20,6 +20,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeBuildingJob; import engine.math.Bounds; +import engine.math.Vector2f; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.client.ClientConnection; @@ -45,7 +46,7 @@ public enum BuildingManager { BUILDINGMANAGER; public static HashMap> prop_meshes = new HashMap<>(); - public static HashMap mesh_heights = new HashMap<>(); + public static HashMap mesh_heights = new HashMap<>(); public static HashMap>> mesh_triangle_points = new HashMap<>(); public static HashMap mesh_bounding_boxes = new HashMap<>(); @@ -993,7 +994,8 @@ public enum BuildingManager { return; //no data for this mesh Mesh generatedMesh = new Mesh(); - generatedMesh.meshHeight = building.loc.y + mesh_heights.get(mesh); + generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x; + generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y; ArrayList> triPoints = mesh_triangle_points.get(mesh); if (mesh_bounding_boxes.containsKey(mesh)) { diff --git a/src/engine/net/client/handlers/MoveToPointHandler.java b/src/engine/net/client/handlers/MoveToPointHandler.java index 896eb89f..4c3e33bc 100644 --- a/src/engine/net/client/handlers/MoveToPointHandler.java +++ b/src/engine/net/client/handlers/MoveToPointHandler.java @@ -47,7 +47,7 @@ public class MoveToPointHandler extends AbstractClientMsgHandler { HashSet awoList = WorldGrid.getObjectsInRangePartial(pc.loc, movementDistance, MBServerStatics.MASK_BUILDING); for(AbstractWorldObject awo : awoList){ Building building = (Building)awo; - if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight())){ + if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight(),pc.loc.y)){ ChatManager.chatSystemInfo(pc, "Collision Detected"); //msg.setEndCoord(); MovementManager.movement(msg, pc);