- Home /
How do I make raycasting work with easyAR's camera?
I want to use the EventSystem to detect a click on a sprite child of ImageTarget. I add the Physics 2D raycaster to the RenderCamera(EasyAR_Startup->ARCamera->RenderCamera) and a BoxCollider 2D to the sprite. It doesn't work. It works fine if I just use a normal camera(GameObject->Camera) on a non-AR experience though.
This is the component that I want to add to the sprite and make it work:
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickAction : MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("clicked");
}
}
Note: I put the vuforia tag because I couldn't find easyAR tag, and just thought that maybe vuforia users have the same problem and can help.
It's a sprite, it should work with physics 2D. And like I said, the code works on a non-AR experience.
I know, but give it a try. $$anonymous$$aybe 2D physics doesn't work in AR for some reason. I never used it in AR, I don't know if it has some limitations. Also, what do you mean by "under the ImageTarget"? Is it a child of the ImageTarget or is it hidden behind it?
Answer by hec_91 · Dec 10, 2018 at 02:33 PM
I tried to do the same and it doesn't work for me either, but only if I use 2D physics. The thing with 2D is that colliders are only drawn on the XY plane, so they aren't affected by rotation, as you can see in this image: So the sprite can rotate as you want, but the collider won't. This means that if the collider is perpendicular to the camera, it will appear as just a line, so it won't work.
Instead, using 3D physics it works just fine. I would advise you to do this: - Create a new material that uses the standard shader. - Set the rendering mode to Cutout and put your sprite into the Albedo field. - Put a quad or a plane in the scene and assing this material to it. - Put a 3D BoxCollider and your script on the new game object. - On the RenderCamera put a 3D Physics Raycaster, maybe with a Max Ray Intersection greater than 0 if you need it.
In my scene, it works.
Your answer
![](https://koobas.hobune.stream/wayback/20220612183656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help, Use event system IPointerClickHandler 1 Answer
How do ı acces dji matrice100 camera in my augmented reality application?(Using vuforia sdk) 0 Answers
Vuforia model target fails in Unity 2 Answers
Using Physics Raycaster and mouse move RaycastHit 0 Answers
Physics.Raycast only finds some objects 0 Answers