How to make character stop when facing the wall

Yeah, I think that would work when walking forward, but what if I walked backwards, sideways or diagonally? It would be weird if my character kept moving towards the wall in any of these directions. How could I make the trace follow the direction I’m walking?