Search Unity

Physics.checkbox

Discussion in 'Physics' started by kromblite, Apr 10, 2019.

  1. kromblite

    kromblite

    Joined:
    Mar 19, 2014
    Posts:
    72
    I'm trying to get a box to switch between two layers, but before it can do that, it needs to check that there's nothing occupying a certain collision box trigger.
    Initially, I used "on trigger enter" and "on trigger exit" and just counted how many objects entered and exited its trigger.
    However, this will not work, because objects that are destroyed while in the box are not taken into account, nor are objects that start the scene already inside the trigger.

    So I'm trying to use "physics.checkbox" instead, but I can't seem to find any good documentation on it. The official documentation doesn't provide any examples, and any forum posts about it are full of people recommending the "onTriggerEnter" method instead.
    Because of this, I am having trouble figuring out how to get this to work.

     public bool empty=true;
    public GameObject returnParent;
    private Vector3 selfCol;

    void Awake(){
    selfCol = GetComponent<BoxCollider> ().size;
    }

    void FixedUpdate(){
    empty = Physics.CheckBox (selfCol/2,selfCol);
    }
     
  2. Smasham

    Smasham

    Joined:
    Jan 24, 2017
    Posts:
    5
    use Physics.Checkphere(vector3() , sphere radius); as a condition

    ex if(Physics.CheckSphere(new Vector3(x,y,z), 1))
    empty = true;
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    matkoniecz likes this.