Gun avoids wall

Hello, how would I make my gun not go through the wall and instead avoids it by making the arms go up/down like in the video below?

https://streamable.com/mczcko

Raycast from the arm and change the position depending on the distance it is from the wall

Or use align orientation/align position