How to make a character stop walking when hitting a wall

Thanks for your reply, it worked but it stopped all movement. Do you know a way so I can make the movement backward, right and left work except forward?