- Home /
Physics Collision Layer Programmatically.
Hi guys,
I have a skill system in my game using scriptable objects. Until recently I was using OnTriggerEnter with a Layermask to detect collisions and fire the effects but for some of my new functionality I want to be able to use the point of collision. Therefore I need to use OnCollisionEnter instead.
However I still want my projectiles to only collide with certain layers. I don't want this to be the same for every projectile though, so far the four layers I'm detecting collisions against are enemy, ally, floor and wall. I want the projectiles to be able to collide with any combination of these (and quite probably more layers in the future) as set by a Layermask on the scriptable object in the inspector. It seems a lot more sensible to me to instantiate this programmatically rather than using the Physics Collision Matrix since obviously the matrix would become messy and get out of hand trying to create a layer to interact with each combination of layers.
I googled around this morning expecting to see a lot of results on Unity Answers but it seems like the few questions about it are better resolved by just assigning a new layer where I don't think that's the case in my situation.
Any Ideas?