I'm shooting myself in my FPS game. Help!

Hello, so I recently started using unity and I followed a few toutorials made by Brackeys on youtube. So I used his FPS movement and FPS shooting videos to get started and after a while everything started to come together nicely.
But I realized that if I aimed down at my characters feet (as far as i could) and shot my pistol, I shot myself because the camera is inside of my player. I looked around and i couldn’t find a fix that works for me.

So far I have tried to scale a few things differently which minimized the problem, but not fully.
And I have tried to move my camera outside of my character but that makes my camera stutter and stuff.

I know this sounds pretty dumb but if anyone has a fix I would love to hear it

THere are lots of different ways to solve this. What type of collision are you using for shooting? Raycasts, maybe?

Yes i am using raycasts.

The simplest way is to use the layermask parameter to ignore your player’s layer. The player needs to be on a separate layer than the enemies for this to work.

add a member to your class:

public LayerMask layermask;

This will automatically render a layer mask selector in the inspector, so you can choose the player’s layer.

and then when you do a raycast, you can just add the parameter like this:

(Physics.Raycast(what ever starting point is, whatever your direction is, out hit, Mathf.Infinity, layermask.value);

By the same token, you can set your enemy prefabs to ignore the enemies layer and then they can’t shoot themselves either.

Wait so in which script do i add these lines of code, or do i create a new one or maybe to be more precise, where in my script do i add the second line of code
.
Because i added the first one to my gun script and the layer mask thing appeared.

Right, exactly.
so your gun script should already have a raycast in there somewhere. I’m just suggesting you add the layer mask to that already-existing statement as an additional parameter.

Thanks!!! It helped alot.

Either put the player onto separate layer and filter by layer mask, or request all raycast hits and filter out the player.

Yes thank you for the answer but i have already fixed it, but still thank you!!!