Basically when our player hits a wall he gets stuck and the only way to unstuck him is to walk the direct oposite way of the wall. for instance if you hit a wall on the right you cant walk forward backwards or right (right is intentional) the only way to get out is to walk left.
this is our code for the colission check.
private void OnCollisionStay(Collision collision)
{
// Determine if we can jump
var normal = collision.contacts[0].normal;
if (normal.y > 0)
{
// Hit Bottom
moveAction.ableToJump = true;
moveAction.ableToMoveBackward = moveAction.ableToMoveForward = moveAction.ableToMoveLeft = moveAction.ableToMoveRight = true;
}
if (normal.x > 0)
{
Debug.Log("Object you hit is to your left");
//Hit Left
moveAction.ableToMoveLeft = false;
}
else if (normal.x < 0)
{
Debug.Log("Object you hit is to your right");
//Hit Right
moveAction.ableToMoveRight = false;
}
else if (normal.z < 0)
{
Debug.Log("Object you hit is in front of you");
//Hit Front
moveAction.ableToMoveForward = false;
}
else if (normal.z > 0)
{
Debug.Log("Object you hit is behind you");
//Hit Back
moveAction.ableToMoveBackward = false;
}
}