Snapping to walls

Hey everyone I dont know if this is a weird question or not. But I cant find any examples upon it so if anyone knows any examples or a way to do it can you please help me out on it. So basically I am making a gaming in third person or you can say a TPS. Now I want the player to come in contact with a wall and when you press a designated button he will snap to the wall. Either he is hiding behind the wall or he is dodging bullets. Like for instances Splinter Cell or Gears of war. I know theres a trigger involved but I dont know where to start coding this.

Detect the wall, and keep the player at certain distance from it. Check this documentation: