Im having issues with a NPC not turning to its walking position; This is the only NPC thats having this issue
https://gyazo.com/6db73d4f2057fb32984fab8d5aad3aeb
However I don't think it's actually a problem with my npc pathfinding (Possibly a model issue?)
Code:
if (npc.walkingType == 1 && (!npc.underAttack) && !npc.walkingHome) {
if (System.currentTimeMillis() - npc.getLastRandomWalk() > npc.getRandomWalkDelay()) {
int direction = Misc.random3(8);
int movingToX = npc.getX() + NPCClipping.DIR[direction][0];
int movingToY = npc.getY() + NPCClipping.DIR[direction][1];
if (npc.npcType >= 1635 && npc.npcType <= 1643 || npc.npcType == 1654
|| npc.npcType == 7302) {
NPCDumbPathFinder.walkTowards(npc, npc.getX() - 1 + Misc.random(8),
npc.getY() - 1 + Misc.random(8));
} else {
if (Math.abs(npc.makeX - movingToX) <= 1 && Math.abs(npc.makeY - movingToY) <= 1
&& NPCDumbPathFinder.canMoveTo(npc, direction)) {
NPCDumbPathFinder.walkTowards(npc, movingToX, movingToY);
}
}
npc.setRandomWalkDelay(TimeUnit.SECONDS.toMillis(1 + Misc.random(2)));
npc.setLastRandomWalk(System.currentTimeMillis());
}
}
}
Code:
public static void walkTowards(NPC npc, int waypointx, int waypointy) {
int x = npc.getX();
int y = npc.getY();
if (waypointx == x && waypointy == y) {
return;
}
int direction = -1;
final int xDifference = waypointx - x;
final int yDifference = waypointy - y;
int toX = 0;
int toY = 0;
if (xDifference > 0) {
toX = 1;
} else if (xDifference < 0) {
toX = -1;
}
if (yDifference > 0) {
toY = 1;
} else if (yDifference < 0) {
toY = -1;
}
int toDir = NPCClipping.getDirection(x, y, x + toX, y + toY);
if (canMoveTo(npc, toDir)) {
direction = toDir;
} else {
if (toDir == 0) {
if (canMoveTo(npc, 3)) {
direction = 3;
} else if (canMoveTo(npc, 1)) {
direction = 1;
}
} else if (toDir == 2) {
if (canMoveTo(npc, 1)) {
direction = 1;
} else if (canMoveTo(npc, 4)) {
direction = 4;
}
} else if (toDir == 5) {
if (canMoveTo(npc, 3)) {
direction = 3;
} else if (canMoveTo(npc, 6)) {
direction = 6;
}
} else if (toDir == 7) {
if (canMoveTo(npc, 4)) {
direction = 4;
} else if (canMoveTo(npc, 6)) {
direction = 6;
}
}
}
if (direction == -1) {
return;
}
if (direction == -1) {
return;
}
/*direction >>= 1;
if (direction < 0) {
return;
}*/
//if (npc.moveX != 0 || npc.moveY != 0)
//throw new IllegalStateException("walking multiple times.");
/*try {
throw new Exception();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
npc.moveX = NPCClipping.DIR[direction][0];
npc.moveY = NPCClipping.DIR[direction][1];
//npc.moveY = World.getWorld().getNpcHandler().GetMove(npc.getY(), npcLocation[1] + movey);
npc.getNextNPCMovement();
npc.updateRequired = true;
}