The first idea is that you move the head with some collision detection, instead of just placing it. This would explain that it's slightly off when it collides with some wall.