Search Unity

How to Whitelist Collisions?

Discussion in 'Physics' started by emugod, Mar 28, 2016.

  1. emugod

    emugod

    Joined:
    Nov 22, 2013
    Posts:
    6
    Been googling around and scratching my head about this for a couple days. Last best guess;

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class collisionwhitelist : MonoBehaviour
    5. {
    6.     public GameObject[] whitelist;
    7.  
    8.     void Start()
    9.     {
    10.         foreach(GameObject go in whitelist)
    11.         {
    12.             Debug.Log("yes");
    13.             Physics.IgnoreCollision(go.GetComponent<Collider>(), this.GetComponent<Collider>(), ignore:false);
    14.         }
    15.     }
    16. }
    on object set to a layer 'whitelisted' which is configured by settings->physics to interact with nothing (not even itself). But this doesn't work - best I can guess is that the Layer Based Physics totally override IgnoreCollision()?

    Anyone have any idea how to go about this?

    Immediate use is to make an invisible wall to stop the return of a nice squishy physics (ConfigurableJoint) -based button (and I can foresee many similar uses, for physics gizmo prefabs). Is this even the right way to do this? I've also played with adding a second ConfigurableJoint with no spring, but that seems to be very bad (unpredictable physics behavior, choppy acceleration/deceleration).
     
    Last edited: Mar 29, 2016
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    ya physics settings will override the code you're trying. You cant turn on collisions when they are configured off