Raycasting not hitting any entities or hitting all entities on click

Hey,

So I have tried all the different methods for raycasting that I could find (entity selection, hotspot, simple entity click) and all are giving me different issues. At this point I am unsure if it is a coding issue or if it has something to do with the way the scene is setup.

When I use the hotspot pc.Ray(); with intersectRay, it hits all the entities at the same time and causes issues. The hotspot itself shows as a small portion in the editor, but the triggers seem to go outisde the bounds of the set radius. It also seems like they are “off”, ie. the stove triggers when clicked above it, the smarthub when behind the scene, etc.

When using the entity selection and the simple entity click raycastFirst(), I have set the hotspots to have colliders, however only clicking the smarthub hotspot triggers anything and even then it seems off. The others will not trigger…except sometimes when the camera is positioned a certain way and click a bit away from the collider, it works. It all seems pretty random.

I have tried adding a lineRender, but it won’t persist in the scene, so I am unsure how to properly debug this thing.

I am using orbital controls, and currently the project is at a state where I am using the raycastFirst() and attempting to log out the ray intersection, so only the SmartHub hotspot really works at all. We also forked the original repo from the Model Viewer project, if that matters.

I am able to revert to a more stable version where I am using intersectRay instead and all hotspots get hit if that would be better to troubleshoot.

<Edit: Removed project link>

Any help would be greatly appreciated.

Hi @mhartz,

Try removing the scale on the camera, reset it to 1,1,1:

image

I think that will fix your issue.

2 Likes

In WebVR Labs, I created a list of all the shapes to test against which allowed me to work out which shape is hit first based on distance from the camera. (Basically raycastFirst but for the pc.Shapes that are registered to the list)

1 Like

That was it! Holy cow. Thanks so much.

It makes sense that was the issue to me now. I am not too familiar with 3D tooling like this, I have only dabbled in building tools for our 3D team in Unity as a programmer, so things like cameras and lighting have me lost.

1 Like