How to check for object collision and turn it back?

Hello

I have a object that i want to move around a box, and when hits the wall check for collision and choose a new target to move like this