Attempt to somewhat improve pathfinding. The Lua implementation should be okay, but the engine function has issues.