when 2d character hits wall it shakes/bounces

i am new to this and am making a small 2d game to learn. when my character hits the wall it shakes or bounces if you like. in my first level i made constraints in the script to stop this. however this level is not a square like the first level. is there any way i can make a wall without it making the character shake?

You could create a Ray from the players centre to either side, and then calculate the length of that ray. If the length is < your translation value, then adjust the translation value to match the distance (probably have to account for your collider bounds as well), something like this should suffice:

function CheckMovement()
{
    RaycastHit hitL, hitR;

    if(Physics.Raycast(player.transform.position, Vector3.left, out hitL))
    {
        if(hitL.distance < translationMovementValue)
        {
            translationMovementValue = hitL.distance;
        }
    }

    if(Physics.Raycast(player.transform.position, Vector3.right, out hitR))
    {
        if(hitR.distance < translationMovementValue)
        {
            translationMovementValue = hitR.distance;
        }
    }
}

To be honest, you could probably split that up so that it will only Raycast to the left or to the right when you press the corresponding movement key, which would be better. But that should be a good starting point for now :slight_smile: