Minimum, smallest distance

The object should move in the direction closest to the wall. Unfortunately it didn’t work. How can I best implement this:

Thanks in advance!