Fragile Maze Help

I don’t know if this is a bug, but my hero’s target position is ahead of the hero, but he is moving somewhere else (see image). I don’t know if this is my code’s problem or a bug, but some help is appreciated.

Code: (the intersection dictionary doesn’t do anything for now, I will do something to that later)
Right now I need some help on the problem I mentioned (hero not going the way it’s meant to go)

dist = 16
startRoom = {"x": 18, "y": 19}

def moveUp():
    hero.moveXY(hero.pos.x, hero.pos.y + dist)
def moveDown():
    hero.moveXY(hero.pos.x, hero.pos.y - dist)
def moveRight():
    hero.moveXY(hero.pos.x + dist, hero.pos.y)
def moveLeft():
    hero.moveXY(hero.pos.x - dist, hero.pos.y)

def upClear():
    return hero.isPathClear(hero.pos, Vector(hero.pos.x, hero.pos.y + dist))
def downClear():
    return hero.isPathClear(hero.pos, Vector(hero.pos.x, hero.pos.y - dist))
def rightClear():
    return hero.isPathClear(hero.pos, Vector(hero.pos.x + dist, hero.pos.y))
def leftClear():
    return hero.isPathClear(hero.pos, Vector(hero.pos.x - dist, hero.pos.y))

reverse = {
        "up": "down",
        "down": "up",
        "right": "left",
        "left": "right"
    }
intersections = {}
path = list()

while True:
    last = path[-1] if len(path) > 0 else "up"
    #hero.say(last)

    if upClear():
        command = "up"
        intersections[hero.pos] += command
        if reverse[last] != command:
            moveUp()
            path.append(command)
            continue

    if downClear():
        command = "down"
        intersections[hero.pos] += command
        if reverse[last] != command:
            moveDown()
            path.append(command)
            continue

    if rightClear():
        command = "right"
        intersections[hero.pos] += command
        if reverse[last] != command:
            moveRight()
            path.append(command)
            continue

    if leftClear():
        command = "left"
        intersections[hero.pos] += command
        if reverse[last] != command:
            moveLeft()
            path.append(command)