The below code is from my enemy movement function in my game. As you can see I have tried some debugging, and everything returns normally. FindTarget() returns the player position, I turn both of them into grid (or map if you prefer) coordinates, and then feed them into the pathfinder. But for some reason I always get a null result, and I have no clue why.
Code:
//find grid position of target
Vector2f tarPos = FindTarget();
int tarX = (int)tarPos.x/25;
int tarY = (int)tarPos.y/25;
//find my grid position
int myX = (int)position.x / 25;
int myY = (int)position.y / 25;
System.err.print("target x: " + tarX + " target y: " + tarY + "\n");
System.err.print("start x: " + myX + " start y: " + myY + "\n");
pathFinder = new AStarPathFinder(Map.GetMap(), 100, false);
Path path = pathFinder.findPath(null, myX, myY , tarX, tarY);
if(path == null){
System.out.print("Failure creating path\n");
}
else{
int length = path.getLength();
System.out.println("Found path of length: " + length + ".");
for(int i = 0; i < length; i++) {
System.out.println("Move to: " + path.getX(i) + "," + path.getY(i) + ".");
}
}