Search Unity

AR Core object detection

Discussion in 'ARCore' started by aldian, Sep 25, 2017.

  1. aldian

    aldian

    Joined:
    Jul 28, 2012
    Posts:
    32
    Hey, quick question. Has anyone had any luck with detecting an object as of yet?

    In the HelloWorld example, you can access the out hit param as you would with a normal raycast. But it has no information entailing what game object it hit. For example hit.trasform.gameobject.tag
     
  2. chaosemer

    chaosemer

    Official Google Employee

    Joined:
    Jul 5, 2017
    Posts:
    21
    tomicz likes this.
  3. trilokves

    trilokves

    Joined:
    Nov 30, 2017
    Posts:
    5
    Is there any way of detect the game object?
     
  4. chaosemer

    chaosemer

    Official Google Employee

    Joined:
    Jul 5, 2017
    Posts:
    21
    To raycast against GameObjects, you can continue to use Physics.Raycast.
     
  5. trilokves

    trilokves

    Joined:
    Nov 30, 2017
    Posts:
    5
    I have tried to use Physics.Raycast on Andy object from HelloArExample, but it is not hitting anything. Below is my script.

    Code (CSharp):
    1. Ray raycast = m_firstPersonCamera.ScreenPointToRay(touch.position);
    2.             RaycastHit raycastHit;
    3.             if (Physics.Raycast(raycast, out raycastHit))
    4.             {
    5.                 Debug.LogError("Something Hit");
    6.                 if (raycastHit.collider.name == "Andy")
    7.                 {
    8.                     Debug.LogError("andy clicked");
    9.                 }
    10.             }else{
    11.                 Debug.LogError("No hit detected");
    12.             }
    So, I have edited HelloARController.cs script. Here m_firstPersonCamera is the ARCamera used by Google ARCore, Even though I click on Andy object, it always goes to the else part of first if condition.

    Can you please check if I am missing anything?
     
  6. kdarius43

    kdarius43

    Joined:
    Mar 16, 2015
    Posts:
    151
    any luck on this?
     
  7. trilokves

    trilokves

    Joined:
    Nov 30, 2017
    Posts:
    5
    Hi, I found this sample project on github which does object detection on ar plane, but it is in android studio.
     
  8. trilokves

    trilokves

    Joined:
    Nov 30, 2017
    Posts:
    5
    OK, I have finally figured out why Physics.Raycast not working correctly with andy object. It is by correctly setting box collider. Below are the correct steps to make a ray hit the andy object.

    1) Add box collider component to andy prefab
    2) set center of the box collider as: x:0, y:0.1, z:0
    3) set size of the box collider as: x:0.15,y:0.2,z:0.1

    Or you can set this values visually by drag and drop andy prefab to unity scene editor.

    Hope this helps.
     
  9. LarryTheBrave

    LarryTheBrave

    Joined:
    Nov 20, 2016
    Posts:
    18
    GameObjects need to have colliders in order for raycast to see them, even in ARCore.
    Physics.Raycast out hit and then hit.collider.gameObject can be used to access the GameObject.