AR Camera + Raycast

I have a question like this thanks to everyone for help.
I want to hitraycast from ARcamera to interact with model but it seems that the location of the models (box colision) is not modeled (like setting in editor)
Thank you so much!

Hi! Welcome to the Playcanvas community. :slight_smile:

If I understand well, you are trying to uses AR to interact with virtual models. Using standard RayCast should work in this case. See theses tutorials.

You should be able to see the colision box in the editor if that entity is selected. Note here how the color changes when I enable the colision box on this:

1 Like

thank you for your answer.
collision works fine in normal camera mode, but the collision position in the AR camera appears to be out of place when clicked.

Can you share your project with us to investigate this?

Of course,
https://playcanvas.com/project/706877/overview/web-ar
This is Image target


And a bit problem
i use script to rotation image but pivot not object center.
thanks you.

Did you figure this out? I’m also trying to implement raycast collisions with an AR camera but not getting any results.

Here’s a quick test project.

https://playcanvas.com/project/727652/overview/ar-raycast-test

I moved the aabbShape calculation into the update routine and now it updates the hit marker on click/touch.

There’s something weird about the coordinates calculated around the corners of the cube where the point ends up inside it, almost like it’s being calculated as a sphere or cylinder in some places. But I changed the actual model shape and it doesn’t match up with those either.

I thought maybe the initial rotation of 90 degrees in the AR script to swap Z and Y could be affecting it, but commenting that out has the same result.

Possibly the coordinates are being calculated at a slight angle from the actual box. But I’ve tried adding a child entity with another box rotated to various angles and none of these seem to align.

Video demonstration of bug.

I changed the script to use raycastFirst to detect a rigidbody. I’m using teleport on a second entity to follow the first since the AR script controls entity position directly and would be overridden by a rigidbody. (I did try adjusting it to work with a rigidbody instead but couldn’t get that working.)

Anyway, it seems the result is out of alignment with the original entity (transparent purple), but the raycast detection works perfectly at the location the rigidbody teleports to instead (orange).

Update: Solved

I was derp and called findByName using the rigidbody entity’s own name. Changed that to its target AR entity and now it works perfectly.

It’ll be easy enough to clean this up and have the duplicate entity spawned in a script attached to the target itself.

2 Likes