• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by AliAzin · Feb 16, 2010 at 06:21 AM · collision

How to make colliders to react only with one layer?

Hi, Is there collision layers in unity or any other way to separate different groups of colliders?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by jonas-echterhoff · Feb 16, 2010 at 07:48 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image test84 · Nov 24, 2012 at 12:34 AM 0
Share

Is it available in Unity 4.x?

avatar image Eric5h5 · Nov 27, 2012 at 03:05 AM 0
Share

@test84: Physics layers have been available for a long time (3.4 or possibly earlier).

avatar image
3
Best Answer

Answer by JDonavan 1 · Feb 19, 2010 at 12:26 AM

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 );
 }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fireDude67 · Dec 03, 2010 at 01:52 AM 0
Share

Ins$$anonymous$$d of a for loop, why not use a foreach(Collider collider in ignoreObjects)?

avatar image
7

Answer by stijn · Sep 28, 2011 at 03:13 PM

I realize this was written a while back but somehow this post still comes up when searching.

Unity now has implemented the following method:

Physics.IgnoreLayerCollision

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GeneralV · Nov 27, 2012 at 02:48 AM 0
Share

+1 (in spirit, I don't have the karma!) I found this question in search, so thanks for that!

avatar image thegreatzebadiah · Dec 17, 2012 at 03:09 AM 0
Share

+1 same as above

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Leap motion: how to pickup a custom mesh 0 Answers

Why is my AI not thinking the collisions fast enough? 1 Answer

Problem with collision detection 0 Answers

Collision between rigid body zombie characters. 1 Answer

OnTriggerEnter2D problem on created collider2d and rigidbody2d during runtime 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges