Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Disable ray through object #225

Open
JenniferFalkenstein opened this issue Dec 21, 2022 · 1 comment
Open

[Question]: Disable ray through object #225

JenniferFalkenstein opened this issue Dec 21, 2022 · 1 comment
Labels
question A general question or query about WebXR or react-xr

Comments

@JenniferFalkenstein
Copy link

Hi there,

I have a Plane and a Cube (and light). The Cube is placed behind the Plane and is wrapped within an <Interact /> Element, while the Plane doesn't do anything.
Every time the Cube gets selected it changes the color of the light into another color.

Now I noticed that even if the Plane is in front of the Cube, the ray still goes through the Plane and therefore is able to select the Cube behind, which is not what I want. The Plane should actually block the ray, so the player won't be able to click the Cube behind.

Is there some kind of prop I have to set or is there another way to accomplish this? 😄

@saitonakamura saitonakamura added the question A general question or query about WebXR or react-xr label Jan 16, 2023
@saitonakamura
Copy link
Sponsor Collaborator

saitonakamura commented Jan 16, 2023

@JenniferFalkenstein events are triggered on first interactive target by default

// Otherwise, filter to first hit
const hit = intersections.find((i) => i?.object)
if (hit) intersections = [hit]
. Another option is to provide custom events.filter function

So to block the Cube you'd either need to

  • wrap Plane in Interactive component
  • add event handlers to Plane via useInteraction
  • provide your own logic via events.filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A general question or query about WebXR or react-xr
Projects
None yet
Development

No branches or pull requests

2 participants