Reputation: 595
I am new to Vuforia.
The gameobject to which the script is added, is a 3d object which is made visible on user-defined triggered image.
I know this is not a new question and I have gone through each of the thread/post on official Vuforia discussion blog for that matter but the problem still persists. And the problem seems very fundamental.
I have the following script attached to my gameobject :
void Update ()
{
if (Input.touchCount == 1)
{
// Touches performed on screen
Ray ray;
RaycastHit hit;
Debug.Log ("2");
if(Camera.main != null)
{
Debug.Log ("3");
ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
hit = new RaycastHit();
Debug.Log ("33");
if(Physics.Raycast(ray, out hit))
{
Debug.Log ("4");
}
}
}
}
When I run the scene and touch on the gameobject, the Debug Console shows
2
3
33
BUT NOT 4. Somehow this ray doesn't hit the object.
This script works fine with the normal camera. Could anyone please shed some light on this.
Thanks
Upvotes: 1
Views: 3498
Reputation: 51
If you are trying take a hit with RayCast on 3d model, you should sure add Box Collider Component on 3d model.
Upvotes: 3
Reputation: 370
I think this is a bug between Collider class and ARCamera, but the solution is this:
Test with any hit algorithm(touch or mouse)
using System.Collections;
using UnityEngine;
public class rayoPrueba : MonoBehaviour {
void start () {print("entro"); }
void Update() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, 100))
print("Si le jue");
}
}
Replace the mainCamera for ARCamera
The trick is... Never lose a gameObject with Collider Component from the scene..
Upvotes: 3
Reputation:
(as far as I can tell) Vuforia doesn't use the ARCamera for collision detection. Instead there is another 'Background Camera' (you can see it if you run your app in Unity and pause it; you'll find it in the Hierarchy pane). To access it use
Camera.allCameras[0]
instead of
Camera.main
Hope that helps
Upvotes: 4