Regarding your sticky wall issue, you need to find out the wall's "normal", that is, the vector it uses to push back against the player, and use it to only nullify the movement components that push it, not the rest.
As a conceptual example, in an axis-aligned environment (All walls are 90ยบ from each other, as if drawn on an square grid) where +X is right and +Y is up, a right facing wall would nullify -X movement, but not the rest.
In the following off the top of my head code, colliding with the wall sets the appropriate
isColliding* flag to
true based on the orientation of the wall, so when the player attempts to move:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| void movePlayer(int newXvelocity, int newYvelocity) { if( (newXvelocity > 0 && isCollidingRight()) || (newXvelocity < 0 && isCollidingLeft()) ) { playerXvelocity = 0;
} else { playerXvelocity = newXvelocity; }
if( (newYvelocity > 0 && isCollidingUp()) || (newYvelocity < 0 && isCollidingDown()) ) { playerYvelocity = 0;
} else { playerYvelocity = newYvelocity; } } |
You should really take a look at vector arithmetic, though, specially if you don't want axis-aligned walls.