diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index 9509b07b..7ffbcf6b 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -121,13 +121,10 @@ public class Terrain { Vector2f terrain_cell = new Vector2f(terrainLoc.x / this.cell_size.x, terrainLoc.y / this.cell_size.y); - // Clamp values when standing directly on max pole + // Clamp values when standing directly on pole - if (terrain_cell.x >= this.cell_count.x) - terrain_cell.x = terrain_cell.x - 1; - - if (terrain_cell.y >= this.cell_count.y) - terrain_cell.y = terrain_cell.y - 1; + terrain_cell.x = Math.max(0, Math.min(this.cell_count.x - 1, terrain_cell.x)); + terrain_cell.y = Math.max(0, Math.min(this.cell_count.y - 1, terrain_cell.y)); return terrain_cell; }