Raycast2D not working as expected

I am attempting to make a hitscan gun for my 2d fighter. I am creating a mask so the raycast ignores the player that is shooting like so:

` int mask = ~(1 << 12 + CurrentPlayer);
RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, Mathf.Infinity, mask);
if (hit.collider != null)

With this as my layer setup: alt text

This is not working, and I am having a lot of trouble figuring out why. I am able to get the raycast to detect the shooting player by removing the mask, but never anything else. Any help would be appreciated, thanks!

Have you actually debugged your mask? I guess not. I’m not sure which range your CurrentPlayer variable will have and if your first player is represented by a value of 0 or 1. It also would be more clear when using brackets like this:

int mask = ~(1 << (12 + CurrentPlayer));

This assumes that CurrentPlayer will be 1 for the first player and 2 for the second. If 0 is the first player and 1 is the second you have to use:

int mask = ~(1 << (13 + CurrentPlayer));