Dynamic height based penalty

Hello, I am currently working on a 2d game in 3d space, I am wanting to change how the path is calculated during run time based on applying a penalty to traversing upward (positive Y) where the game object is and where it needs to go. currently it works fine but if its target is on a level above them on another level the path calculates straight up then left or right, it finds itself getting stuck trying to move straight up instead of left or right. I have played with position penalty but it tends to lead to an error*. any advice/guidance would be greatly appreciated.

*Very high penalty applied. Are you sure negative values haven’t underflowed?
Penalty values this high could with long paths cause overflows and in some cases infinity loops because of that.