,How to fix Main Camera's off set when following 3d player

In my project, I have made a first person player but this time you can actually see your body. If I Look down or up, my character’s torso will move up and down. I then set the main camera as a child onto the player and made a script for the camera to follow the player and move up and down with him. However, the camera goes through my legs. I’ve tried to adjust the offset but nothing seems to work.
How do I fix this?

If the camera is a child of the player, the camera will follow the player automatically. If the player turns and the camera is far from the player, the camera will move very fast. This is rarely what you want. I would suggest moving the camera out of the player. It should be its own entity, and then it should have a script attached to it that makes it follow the player in LateUpdate. You need to do it in LateUpdate so you are sure that all of the physics and scripts that move the player are finished before you update the camera position.

using raycast from the back of the head of the player (at chosen angle) could work well with finding a spot to place the camera. this way u can place it at the end of the raycast or closer if the raycast hits some objects (to avoid camera clipping).