Hi, Is there collision layers in unity or any other way to separate different groups of colliders?
I realize this was written a while back but somehow this post still comes up when searching.
Unity now has implemented the following method:
For example:
// ignore collisions between first 2 custom layers
Physics.IgnoreLayerCollision( 8, 9 );
I realize this was written a while back but somehow this post still comes up when searching.
Currently there is only Physics.IgnoreCollision(), which acts per collider, not per layer, so, likely you have to write some more complex setup code for what you want. We are working on improving this in the future.
Ryan Scott posted a script to the UnifyWiki site that might help...
From http://www.unifycommunity.com/wiki/index.php?title=CollisionIgnoreManager
using UnityEngine;
using System.Collections;
// Anything provided to this manager will have its collisions with anything else registered
public class CollisionIgnoreManager : MonoBehaviour {
public static CollisionIgnoreManager collisionIgnoreManager = null;
ArrayList ignoreObjects = new ArrayList();
ArrayList ignoreMasks = new ArrayList();
public static CollisionIgnoreManager getSingleton() {
return collisionIgnoreManager;
}
// Use this for initialization
void Start () {
if( collisionIgnoreManager == null )
collisionIgnoreManager = this;
}
// Update is called once per frame
void Update () {
// clean up any dead objects
for( int i = ignoreObjects.Count - 1; i >= 0; i-- ) {
if( ignoreObjects[ i ] == null ) {
ignoreObjects.RemoveAt( i );
ignoreMasks.RemoveAt( i );
}
}
}
public void addIgnore( Collider newCollider ) {
addIgnore( newCollider, 0xffff, 0xffff );
}
public void addIgnore( Collider newCollider, int thisMask, int mask ) {
for( int i = 0; i < ignoreObjects.Count; i++ ) {
Collider collider = ignoreObjects[ i ] as Collider;
if( collider != null && ( mask & ( (int) ignoreMasks[ i ]) ) == mask )
Physics.IgnoreCollision( newCollider, collider, true );
}
ignoreObjects.Add( newCollider );
ignoreMasks.Add( thisMask );
}
}