3 Answers
3

A simple solution would be to implement a check during your movement code. If the player attempts to move right, check if there is an object that would stop the object moving in that tick and if so move the player next to that object and set the velocity to 0.

There are many solutions, depending on what kind of effect you want to achieve. Here's a simple 'rebound' solution:

When a collision between object 'A' and the wall is detected, do the following:

Get a Vector V_r which points from the collision point to A's center point (let's call the center point P_A ).

Set the object's new position P_An = P_A + (V_r * d), where d is a distance. This distance must be so, that after you set P_An, the object is no longer colliding with the wall. So d depends on your collision detection method. With pixel perfect collision, d must be large enough to put P_An on a different pixel than which P_A is on.

Let's name the object's velocity vector right before the collision V_v.

Set the object's new velocity to V_vn = -V_v * c, where c is a constant value somewhere between zero and one. This will provide the effect of some "inertia loss".