Camera clipping into character's mesh

Hi, i’m working on a fps game, the problem i have is that if i attach the camera to the head bone, the camera will shake when the animation shake the mesh’s head.
If i don’t attach the camera to the mesh it will clip into the character’s mesh when he is leaning, i tried to change the position of the camera manually, this ends up making the camera doing really strange thing. Here’s the code i used to move the camera with the head’s bone in my character’s tick function :

if(GetCurrentCameraMode() == ECameraMode::CM_FirstPerson)
			{ 
				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, TEXT("trying to cast CameraManager"));
				APlayerController* PC = Cast<APlayerController>(GetController());
				APlayerCameraManager* CameraManager = Cast<APlayerCameraManager>(PC->PlayerCameraManager);
				if (CameraManager)
				{
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("CameraManager Cast succeed"));
					FVector HeadLocation = GetMesh()->GetSocketLocation(FName("HeadSocket"));
					FVector CameraLocation = CameraManager->GetCameraLocation();

					if (HeadLocation != CameraLocation)
					{
						if (HeadLocation.X != CameraLocation.X)
						{
							CameraComp->AddAdditiveOffset(FTransform(FQuat(), FVector(HeadLocation.X - CameraLocation.X, 0.0f, 0.0f)), CameraComp->FieldOfView);
						}

						if (HeadLocation.Y != CameraLocation.Y)
						{
							CameraComp->AddAdditiveOffset(FTransform(FQuat(), FVector(0.0f, HeadLocation.Y - CameraLocation.Y, 0.0f)), CameraComp->FieldOfView);
						}

						if (HeadLocation.Z != CameraLocation.Z)
						{
							CameraComp->AddAdditiveOffset(FTransform(FQuat(), FVector(0.0f, 0.0f, HeadLocation.Z - CameraLocation.Z)), CameraComp->FieldOfView);
						}
					}
				}
			}

I think this is correct, maybe the camera’s not supposed to be moved like that or i am doing something wrong ?
Thank you for helping me !