Raycasts ignoring colliders based on Collider Name

Hello

I have a small problem with a FPS game im making currently, the issue is, if i fire at a too low angle i will hit my own collider, and therefore kill myself, now this is certainly not intentional and i've been trying to find various ways to fix it.

What i want to do, is to have the ray ignore the collider on the player, your own collider. This can be easily solved by using a layer. But, the prefab that you use gets instantiated whenever a player joins, so if i put my own player on a "ignore raycast" layer, the other players will be ignored as well.

I have tried using a if-sentence to stop the ray from killing myself, but as i have hit a collider the ray wont continue.

What i think would work, was if i could ignore colliders based on their name, since the name of the prefab gets randomized for every player that joins. Any ideas on how to do this?

Edit/Update:

I seem to have figured out how to fix my issue, what i am going to do is to limit the maximum amount of players on the server at a time to 16. Then when a player joins, he is put onto a layer of his own, which will then be ignored by him, and him only.

The only problem i have with this, is that i have no idea how to fetch/make an ID based on the player who joins, im looking for a single/double-digit integer which i can use to assign a layer to a player.

I hope someone can help me with this :)

Thanks in advance

Seth

Take a look at giving your GameObjects a tag

So give your player his own tag, and the other players another tag..

Then do something like

if (other.gameObject.tag == "MyPlayer") 
// Ignore raycast here

@Kacer The solution is to use the physics engine’s layers system and then tell the raycast to only collide with the specific layers that you need it to.