### Player Sticking to Walls

Hey guys,

I've been trying to make a game and I ran into an interesting problem. I have currently programmed a player that can move around, a box that represents a wall, and a collision detection function. My problem is that the player will stop when he collides with a wall, but then he can't move away or slide along it. So how do I get rid of this "sticky" wall?

Collision Detection Function

 ``123456789101112`` ``````bool GameSys::check_collision( SDL_Rect A, SDL_Rect B ) { if ( ( A.y <= ( B.y + B.h ) ) && ( ( A.y + A.h ) >= B.y ) && ( A.x <= ( B.x + B.w ) ) && ( ( A.x + A.w ) >= B.x ) ) { return true; } return false; }``````

Detect Collision (transfers collision detection results to the player class)

 ``1234`` ``````void Player::detect_collision( bool co ) { collision = co; }``````

Player Movement Function

 ``12345678910111213141516171819202122`` ``````void Player::move_player() { plyr_to.x += plyr_speedX; plyr_to.y += plyr_speedY; plyr_co_box.x += plyr_speedX; plyr_co_box.y += plyr_speedY; if ( plyr_co_box.x <= 0 || ( plyr_co_box.x + plyr_co_box.w ) >= 640 || collision == true ) { plyr_to.x -= plyr_speedX; plyr_co_box.x -= plyr_speedX; } if ( plyr_co_box.y <= 0 || ( plyr_co_box.y + plyr_co_box.h ) >= 480 || collision == true ) { plyr_to.y -= plyr_speedY; plyr_co_box.y -= plyr_speedY; } }``````

 ``12345678910111213141516171819202122232425262728`` ``````void Player::move_player() { if ( plyr_co_box.x <= 0 || ( plyr_co_box.x + plyr_co_box.w ) >= 640 || collision == true ) { plyr_to.x -= plyr_speedX; plyr_co_box.x -= plyr_speedX; } else { plyr_to.x += plyr_speedX; plyr_co_box.x += plyr_speedX; } if ( plyr_co_box.y <= 0 || ( plyr_co_box.y + plyr_co_box.h ) >= 480 || collision == true ) { plyr_to.y -= plyr_speedY; plyr_co_box.y -= plyr_speedY; } else { plyr_to.y += plyr_speedY; plyr_co_box.y += plyr_speedY; } }``````