Search Unity

How to get AR Foundation ARCamera to interact with collider triggers?

Discussion in 'Handheld AR' started by ethanproia, Jun 14, 2019.

  1. ethanproia

    ethanproia

    Joined:
    Feb 27, 2019
    Posts:
    7
    Hello all,
    Working on a location-based AR experience in AR Foundation. I'm trying to make UI text trigger when the ARCamera (user position) interacts with a box collider trigger attached to a placed object.

    The object I'm placing that I want to act as the movable trigger is a prefab for the provided PlaceOnPlane script. I've written a second script telling the collider to trigger a specified UI text when the ARCamera tagged MainCamera intersects with the placed object collider/trigger. For some reason, the ARCamera, even when tagged with the proper tag as directed by my script, will not register or display the text or register the collision. Can the ARCamera not be used to interact with colliders or trigger objects? I've got rigidbodies on the collider/trigger and the ARCamera.

    The code for the trigger/collider is

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PoemTrigger : MonoBehaviour {
    6.  
    7.     public GameObject poemText;
    8.     void Start()
    9.     {
    10.         poemText.SetActive(false);
    11.     }
    12.     void OnTriggerEnter(Collider camera)
    13.     {
    14.         if (camera.gameObject.tag == "MainCamera")
    15.         {
    16.             poemText.SetActive(true);
    17.             StartCoroutine("WaitForSec");
    18.         }
    19.     }
    20.     IEnumerator WaitForSec()
    21.     {
    22.         yield return new WaitForSeconds(5);
    23.         Destroy(poemText);
    24.     }
    25. }
    Been stuck on how to solve this for a few days now. Any help or suggestions would be very appreciated. Thank you!
     
    lkdin, eaglecondor and vovo801 like this.
  2. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    8
    Hey, i'm trying to do the same things, but with an object. I'm also trying to solve this problem. Have you tried setting a rigidbody and a collider in the camera?
     
    lkdin likes this.
  3. lkdin

    lkdin

    Joined:
    Jun 29, 2018
    Posts:
    10
    Having the same problem here
     
  4. mubeenfa

    mubeenfa

    Joined:
    Dec 14, 2016
    Posts:
    1
    I attached a rigid body and box collider component to my camera at run-time.
    For Box collider scale, you need to manually scale the collider in Editor. Once you got the perfect size, define it in your code.
     
unityunity