- Home /
Layers of collision in Unity (or something similar)? (C#)
Hey, I'm in need of some way to ignore a large amount of objects at instantiation. Is there some way to set layers of collision in Unity such that an object can ignore a specific collision layer?
More specifically, my game requires a large amount of bullet objects. I am looking for some way for these bullets to collide with most of the objects in the scene but ignore the rest. Mostly I need the bullets to ignore other bullets in the scene. The only way I know of to do this is to use the IgnoreCollision() method, but there can be dozens or even hundreds of bullets in the scene at one time. I need a computationally quick way to ignore collisions with the rest of these bullets when a new bullet is instantiated.
I did some investigating and it seemed like this was a known requested feature some time ago, but I'm hoping there is some way to do this now. So, can anyone think of any way to do this other than somehow obtaining all of the bullets in the scene and iterating through all of them for each new bullet, ignoring collisions one at a time?
Answer by Bunny83 · Jul 27, 2012 at 03:31 AM
Just set your bullet-prefab to a seperate layer (a bullet layer). Then all you need to do is go to the physics manager (Edit->Project Settings->Physics) and setup the collision matrix as you wish.
That seems to be exactly what I was looking for! Thanks!
Also, if anyone else needs this information, How to set layers for prefabs: http://docs.unity3d.com/Documentation/Components/Layers.html
Your answer
Follow this Question
Related Questions
How to set up the CollisionIgnoreManager script to ignore a layer (C# question) 2 Answers
Physics.IgnoreLayerCollision - Help 2 Answers
Enable / Disable Layer Collision Matrix thru Script 1 Answer
Ignore collisions between a certain collider and a layer 2 Answers
How to create User layer that acts like the "Ignore Raycast" layer? 1 Answer