Search Unity

Bounds.Intersects() Not Working?

Discussion in 'Scripting' started by renman3000, Aug 7, 2019.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I am using Bounds.Intersects() to check if a bounds intersects with another.

    My issue is that, that return is true, when visually it is not. My only guess of potential issue is that one of the bounds in on a half pipe, so a convex shape.

    Anyone have any guesses? Tips?


    Code (CSharp):
    1.     void checkIfCanLand(){
    2.         //print("check " + Time.time);
    3.         bool canLand = true;
    4.         for(int i = 0; i < bodyBounds.Length; i++){
    5.             if (bodyBounds[i].Intersects(pipeBounds))
    6.             {
    7.                 print(" body bounds i " + playerBodyBits[i].transform.name + ", is intersecting");
    8.                 canLand = false;
    9.             }
    10.             else
    11.             {
    12.                 print("no " + i);
    13.             }
    14.         }
    15.         if (canLand)
    16.         {
    17.             tf_skier.localEulerAngles = cachedRtnAtLaunch;
    18.             PlayerRtnZ.ins.landPlayer();
    19.             isLaunched = false;
    20.         }
    21.         else
    22.         {
    23.             print("CRASH!! ");
    24.             Time.timeScale = 0;
    25.         }
    26.     }
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Bounds represents an axis-aligned bounding box that surrounds the entire object. A half pipe or ramp shape will have a considerably larger bounds than the visual mesh.