Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

why does a ball in an enclosed box fall thru when using vuforia ?

Discussion in 'Vuforia' started by terBlue, Apr 11, 2018.

  1. terBlue

    terBlue

    Joined:
    Jun 11, 2015
    Posts:
    2
    Hey Guys,

    I am new and wanted to create a 'box' with a ball inside. Using a target page, the box would display and I was wondering if you slant the target page, would the ball round around inside the box. From there, i was thinking of making a maze.

    So i created a box using cubes, and i created a ball using a sphere and put a rigidbody on it. To keep the ball in the box, i created a top using a cube and turned off its mesh rendering. If i test the box with the ball, i can rotate it and the ball rolls around and does not fall out.

    But once i put the box on a target page, and run vuforia, the 'ball' just FALLS, as if there are no boundaries at all, and i am just left with box. how can the ball fall thru the box ?

    Is there an option i need to set to get the 'ball' to behave correctly ?

    Am using Unity 2017.3 and the vuforia version that supports. On a mac and building for android Samsung 7

    thx
    Thea
     
  2. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Hi Thea,

    on your ImageTarget prefabs have a look at the DefaultTrackableEventHandler script.
    When your tracking state changes and you don't have tracking OnTrackingLost() get's called, your GameObjects stay active but their Colliders are disabled.

    Code (CSharp):
    1.  
    2.     protected virtual void OnTrackingLost()
    3.     {
    4.         var rendererComponents = GetComponentsInChildren<Renderer>(true);
    5.         var colliderComponents = GetComponentsInChildren<Collider>(true);
    6.         var canvasComponents = GetComponentsInChildren<Canvas>(true);
    7.  
    8.         // Disable rendering:
    9.         foreach (var component in rendererComponents)
    10.             component.enabled = false;
    11.  
    12.         // Disable colliders:
    13.         foreach (var component in colliderComponents)
    14.             component.enabled = false;
    15.  
    16.         // Disable canvas':
    17.         foreach (var component in canvasComponents)
    18.             component.enabled = false;
    19.     }
    Since the GameObjects are still active and your RigiBody is still active it can fall right through your carefully constructed box.
    You might want to replace DefaultTrackableEventHandler with your own implementation. ( Maybe disable GameObjects compeletly, see what works for you. Every specific approach has it's own advantages and disadvantages. ) I would advise to use a different script file and class name and replace DefaultTrackableEventHandler on the ImageTarget, because if your edit DefaultTrackableEventHandler directly your implementation will get overwritten with each Vuforia SDK update.
     
    Vuforia-Strasza likes this.
  3. terBlue

    terBlue

    Joined:
    Jun 11, 2015
    Posts:
    2
    Thank You, i was just looking at this, and noticed that the colliders get turned off. Am wondering why that needs to be done ? Seems like a bug to me, but perhaps there is a valid reason.

    Thea
     
  4. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    I think the Colliders get turned off so that you can't interact with the active & invisible ( not rendered ) GameObjects. I often need that so that GameObjects don't receive touch inputs. There are several alternative approaches thinkable. But all have their own benefits and disadvantages. ( For example disabling GameObjects completely would prevent them from running background code in the Update loop. ) But you should adjust the code to what fits your particular needs.
     
  5. salvator12

    salvator12

    Joined:
    Dec 20, 2018
    Posts:
    1
    my DefaultTrackableEventHandler in Image Target have the script above. but it is still FALL. So, is there any solution?