Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

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

Discussion in '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!
     
  2. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    24
    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?
     
    gibbrish123 and lkdin like this.
  3. lkdin

    lkdin

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

    mubeenfa

    Joined:
    Dec 14, 2016
    Posts:
    4
    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.
     
  5. gibbrish123

    gibbrish123

    Joined:
    Feb 29, 2020
    Posts:
    8
    I'm struggling with this too. Could you demonstrate the steps and provide an example @mubeenfa ?? It would really help. Thank you.

    upload_2020-4-2_17-13-15.png
     
  6. gibbrish123

    gibbrish123

    Joined:
    Feb 29, 2020
    Posts:
    8
    I'm trying to do this too.... Were you able to solve it?? Please share any progress you've made. It would really help. Thank you.
     
  7. gibbrish123

    gibbrish123

    Joined:
    Feb 29, 2020
    Posts:
    8
    Hello..... Amazing that you were able to solve it. The same approach isn't working out for me for some reason. Could you please throw some light on it?? Would really appreciate that, thanks in advance.
     
  8. JcFractal

    JcFractal

    Joined:
    Jan 28, 2016
    Posts:
    2
    I got it working by putting a game object as a child of the AR camera, then I put a rigid body(no gravity) and the collider on it. Then just place the gameobject you want to walk into with a collider set as trigger.​
     
    arialblack14, jipsen and gibbrish123 like this.
unityunity