- Home /
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
It would be simpler if you started the raycast outside the collider. Then you wouldn't have to worry about hitting it.
Doesnt the raycast begin at the camera's near surface?
It does indeed sound like a solution, but im unsure about how to implement it :)
perhaps i should check up with the documentation before commenting, derp, i'll look into it.
Answer by Chiroculon · Apr 06, 2017 at 10:04 PM
@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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613131353im_/https://answers.unity.com/themes/thub/images/avi.jpg)