Making an object only movable parallel to another object in a 3D scene

hey guys, so I set up this farm environment and I want a farmer object to move up, down, left and right in his field. But I only want him to move parallel to the fences so the x and z coordinates have to be de- or increased in the right proportions. Any idea how I can code this? I really have no clue how to solve this problem.

Edit: The only solution I have found till now is, to reorganize the field so it is at the x and z axis. Than I only have to in or decrease one coordinate for the movement.

There’s probably some math for that. xpos/zpos or something, idk. I realize I’m not being that helpful lol

Just set up a quick nav mesh, and set your farmer on the path