I’ve had this problem many times before. isPathClear sometimes detects that the path is clear when it’s not, messing up perfectly good algorithms. Sometimes, you can move a bit closer to the obstacle and isPathClear will suddenly return false, but in your situation, I’m not sure that will work. Honestly, I just hard-coded the jumps for this map because I was so tired of dealing with isPathClear.
It’s kinda hacky, but there is a way around this.
- Store the result of hero.findHazards() in a variable
- Iterate through hero.findHazards() until you detect one that is exactly xOffset, yOffset away (i.e. let’s say the mines are spaced 10 apart, you’d want to check an xOffset of 10 and a yOffset of 0). If one isn’t found, the path is clear. If it is found, the path isn’t clear (make your own function for this to make it easier, but call it something other than isPathClear because the name is taken)