AR Core object detection

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

Raycasts in ARCore hit (real world) planes, not game objects. You can see the plane that is hit in the Plane member of TrackableHit.

1 Like

Is there any way of detect the game object?

To raycast against GameObjects, you can continue to use Physics.Raycast.

I have tried to use Physics.Raycast on Andy object from HelloArExample, but it is not hitting anything. Below is my script.

Ray raycast = m_firstPersonCamera.ScreenPointToRay(touch.position);
            RaycastHit raycastHit;
            if (Physics.Raycast(raycast, out raycastHit))
            {
                Debug.LogError("Something Hit");
                if (raycastHit.collider.name == "Andy")
                {
                    Debug.LogError("andy clicked");
                }
            }else{
                Debug.LogError("No hit detected");
            }

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?

any luck on this?

Hi, I found this sample project on github which does object detection on ar plane, but it is in android studio.

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.

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.