Fix issues with sliding against walls

Reverting most of commit 06fb82e01fcbd880eec80a9ce3d5128091f76921.