mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 22:03:12 +00:00
Smoother + Most-Cost Effective Flight Pathing
This commit is contained in:
1 parent
960b223155
commit
a79ba3a0e4
3 files changed
+114
-14
No files matched your search
@@ -173,7 +173,8 @@ public class FlyPathFinder extends PathFinder {
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
NPCPathPoint pathpoint5 = this.pathOptions[j];
|
||||
float f1 = pathpoint4.totalPathDistance + this.getTraversalCost(pathpoint4, pathpoint5);
|
||||
float f1 = pathpoint4.totalPathDistance + this.getTraversalCost(pathpoint4, pathpoint5)
|
||||
+ this.getDirectionalPenalty(pathpoint4, pathpoint5, p_75861_3_);
|
||||
|
||||
if (!pathpoint5.isAssigned() || f1 < pathpoint5.totalPathDistance) {
|
||||
pathpoint5.previous = pathpoint4;
|
||||
@@ -211,6 +212,24 @@ public class FlyPathFinder extends PathFinder {
|
||||
return DIAGONAL_3D_COST;
|
||||
}
|
||||
|
||||
private float getDirectionalPenalty(NPCPathPoint from, NPCPathPoint to, NPCPathPoint goal) {
|
||||
int stepX = to.xCoord - from.xCoord;
|
||||
int stepY = to.yCoord - from.yCoord;
|
||||
int stepZ = to.zCoord - from.zCoord;
|
||||
int goalX = goal.xCoord - from.xCoord;
|
||||
int goalY = goal.yCoord - from.yCoord;
|
||||
int goalZ = goal.zCoord - from.zCoord;
|
||||
int stepLen = Math.abs(stepX) + Math.abs(stepY) + Math.abs(stepZ);
|
||||
int goalLen = Math.abs(goalX) + Math.abs(goalY) + Math.abs(goalZ);
|
||||
|
||||
if (stepLen == 0 || goalLen == 0) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
float alignment = (float) (stepX * goalX + stepY * goalY + stepZ * goalZ) / (float) (stepLen * goalLen);
|
||||
return (1.0F - alignment) * 0.04F;
|
||||
}
|
||||
|
||||
private float estimateCostToTarget(NPCPathPoint from, NPCPathPoint to) {
|
||||
float dx = Math.abs(to.xCoord - from.xCoord);
|
||||
float dy = Math.abs(to.yCoord - from.yCoord);
|
||||
|
||||
Reference in new issue
Block a user