This commit is contained in:
2023-11-07 21:45:16 -06:00
parent 1b5738f9b3
commit c426a84db0
4 changed files with 63 additions and 38 deletions
+26 -19
View File
@@ -3,6 +3,8 @@ package engine.gameManager;
import engine.math.Vector3fImmutable;
import engine.objects.*;
import java.awt.*;
import java.awt.geom.Path2D;
import java.util.ArrayList;
@@ -12,18 +14,19 @@ public class NavigationManager {
private static final int stepHeight = 2;
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
//try {
// ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
// if (path.isEmpty()) {
// character.destination = goal;
// return; //no points to walk to
// }
try {
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
if (path.isEmpty() || path.size() < 2) {
character.destination = goal;
return; //no points to walk to
}
// character.destination = path.get(0);
//character.destination = path.get(1);
character.navPath = path;
//} catch(Exception e){
} catch(Exception e){
//something failed
//}
}
}
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
@@ -101,16 +104,20 @@ public class NavigationManager {
public static boolean pointIsBlocked(Vector3fImmutable point) {
Building building = BuildingManager.getBuildingAtLocation(point);
if(building != null)
for(Regions region : building.getBounds().getRegions())
if(region.isPointInPolygon(point))
if(Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
if(building != null) {
for (Regions region : building.getBounds().getRegions()) {
if (region.isPointInPolygon(point))
if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
return true;
Zone currentZone = ZoneManager.findSmallestZone(point);
if(currentZone == null)
return false;
else
return currentZone.navMesh.contains(point.x,point.z);
}
boolean pointBlocked = false;
for (Path2D.Float mesh : building.meshes) {
if (mesh.contains((double)point.x,(double)point.z)) {
pointBlocked = true;
}
return pointBlocked;
}
}
return false;
}
}