A pathfinding solution

Thanks for formatting your code :slight_smile:

Now you keep track of both the smallest distance and the pixel that correspond to that smallest distance so everything should be okay for this matter.

I have the feeling that you are calling the arrive() method at the wrong moment however.
I presume it is that method that makes your carnivor move to the target. In this case you want it to be outside you second loop. You first want to loop through all the outside lake pixels and only then, when you found the nearest one, you want to make your carnivor move towards it.