Manually triggering events #1434
Unanswered
stilllovinnero
asked this question in
Q&A
Replies: 1 comment 6 replies
-
yes you can do that but you need to pass a fake event with offsetX/Y so that the raycaster can shoot a ray and see if anything has been hit. additionally you can also call events on meshes and groups directly if you have the reference. you can also override the offset compute function, which is probably best: <Canvas raycaster={{ computeOffsets: e => ({ offsetX: number, offsetY: number }) if you just take the width and height of the canvas and divide it by 2 then you should be able to make all events point to the middle. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all,
tl;dr: How do I trigger click events manually via a button?
I am currently trying to build a first person game in r3f and I am using the build-in onClick events for interactions with objects.
In the desktop version of the game I am using PointerLockControlls and the computeOffset function in the raycaster to detect mouseclicks as if they are made from the middle of the screen. (Visualized by a crosshair)
My problem comes with the mobile version of the game. I want to use the same system with the onClick events, but I want to fire the raycaster via a button not via a touch on the canvas.
Some digging and asking made me think that I could do something like
const {events} = getThree(); events.onClick();
But the events object is returned as "undefined" :/
I also tried to use the intersect method, but I cant find an example for it and I am not sure how to use it. Is there any example code i am missing?
Beta Was this translation helpful? Give feedback.
All reactions