Search Unity

Resolved using Physics.Checkbox is it buggy or just few docmutation on how to use it?

Discussion in 'Physics' started by Keita-kun, Feb 21, 2021.

  1. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi, I tried using Physics.Checkbox since it seemed the easiest way to perform the check I needed but it never worked tried many parameters I always get FALSE for collision detection. even if the object is overlapping an object an other object. for performance and simplicity of code used I am trying to make it with this approach avoid raycasts,enter/exit collision. Specially with new InputSystem the oldway to do checking needs more round trips in my case.

    Code (CSharp):
    1. public static bool CheckBox(Vector3 center, Vector3 halfExtents, Quaternion orientation = Quaternion.identity, int layermask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
    parameters I used to test:
    Code (CSharp):
    1. Vector3 center = _bc.bounds.center;
    2. Vector3 halfExtents =
    3. [INDENT] new Vector3(_bc.bounds.center.x,_bc.bounds.min.y,_bc.bounds.center.z);
    4.  new Vector3(_bc.bounds.size.x / 4, _bc.bounds.size.y / 4, _bc.bounds.size.z / 4);
    5.  new Vector3(transform.localScale.x / 2, transform.localScale.y / 4, transform.localScale.z / 4);[/INDENT]
    Code (CSharp):
    1. Quaternion orientation =
    2.                Quaternion.identity;
    3.                 transform.rotation;
    4. int layermask = 9;
    5. QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGloba
    I always get false no matter what I put in params specially the half extent vector3 one
    if anyone can help thanks.
     
    Last edited: Feb 21, 2021
  2. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Solved: Physics.CheckBox(_boxcollider.bounds.center,_boxcollider.bounds.size/2,transform.rotation, groundSlope)
    wrong assumption that there is no vector division in unity :p Actually, Unity seems to handle it internally on it own way vector/float is ok in Unity. groundSlope is the layer where collision should be checked. I am happy camper, 4 lines of code jumping and no double Jump allowed :)