x


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?

more ▼

asked Jul 27 '12 at 03:28 AM

cr1t1cal gravatar image

cr1t1cal
5 3 4 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jul 27 '12 at 03:31 AM

Bunny83 gravatar image

Bunny83
46.9k 12 50 210

That seems to be exactly what I was looking for! Thanks!

Jul 27 '12 at 03:39 AM cr1t1cal

Also, if anyone else needs this information, How to set layers for prefabs: http://docs.unity3d.com/Documentation/Components/Layers.html

Jul 27 '12 at 03:44 AM cr1t1cal
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2584
x159
x70

asked: Jul 27 '12 at 03:28 AM

Seen: 694 times

Last Updated: Jul 27 '12 at 03:44 AM