hero.isPathClear(😄)

I dont see how this function is returning true.

I had my hero say the X coordinates for my Start and End. Then the Y coordinates for Start and End. Yet their is a mine in the path way. Can someone explain how this is true? Reffering to the isPathClear method.

My cursor is right over the exact coordinates of the mine.

Try not to mind where my hero is jumping. I just want to know why its even inside this elif statment.

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)
2 Likes

Thanks so much. Im glad im not the only one that was losing my mind trying to figure out why this isnt working. I didnt have the slightest clue what I was doing wrong.