title: Unity ARCore touch Object
body: <p>I am currently trying, to detect if a touch input hits a 3D Object in my ARCore scene. I simply edited the HelloAR sample script, to use a custom prefab instead of the andy object, and after i have spawned it, i want to be able to touch it. The prefab consists of six 3D platforms, each with a different name and a box collider. The following code gives very weird results.</p>
  
  <pre><code>        if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
          {
              // Use hit pose and camera pose to check if hittest is from the
              // back of the plane, if it is, no need to create the anchor.
              if ((hit.Trackable is DetectedPlane) &amp;&amp;
                  Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                      hit.Pose.rotation * Vector3.up) &lt; 0)
              {
                  Debug.Log("Hit at back of the current DetectedPlane");
              }
              else
              {
                  if (!IsPointerOverUIObject())
                  {
                      if(!platsSpawned)
                      {
                          // Instantiate platforms at the hit pose.
                          var platforms = Instantiate(platformPrefab, new Vector3(hit.Pose.position.x, hit.Pose.position.y + offsetY, hit.Pose.position.z), hit.Pose.rotation);
  
                          // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                          // world evolves.
                          var anchor = hit.Trackable.CreateAnchor(hit.Pose);
  
                          // Make platforms a child of the anchor.
                          platforms.transform.parent = anchor.transform;
  
                          platsSpawned = true;
  
                      }
                      else if (platsSpawned)
                      {
                          //Ray raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
                          Ray raycast = FirstPersonCamera.ScreenPointToRay(Input.GetTouch(0).position);
                          RaycastHit raycastHit;
  
                          if (Physics.Raycast(raycast, out raycastHit))
                          {
                              try
                              {
                                  debugLabel.text = raycastHit.collider.name;
                                  var obj = GameObject.Find(raycastHit.collider.name);
                                  obj.GetComponent&lt;SomeScript&gt;().DoeSmthng();
                              }
                              catch (Exception ex)
                              {
                                  Debug.Log(ex.Message);
                              }
                          }
                      }
                  }                    
              }
          }
  </code></pre>
  
  <p>Running this code, it will sometimes not hit any platform (even though you are clearly touching them), sometimes it will detect the touch correctly and sometimes it will just hit any of the other platforms in the prefab (even when only one is visible at the moment). </p>
  
  <p>I feel like there is something weird going on with the Raycast. I tried casting with "Camera.main" and "FirstPersonCamera" but the results are pretty much the same. </p>
  
  <p>Any ideas on why this is happening? Does someone have a proper example or can help me to correct my code ?</p>
  
  <p>EDIT: I found out that the RayCasts work as long as the platform Objects are not children of the anchor. I that maybe the Objects might be turned into "Trackables", but i am not sure how i would work with those.</p>