Simulate POINTERTAP && button == 0 within code/game

Hi everyone, I have a little problem which I can’t deal with, well the thing is that I have a BABYLON.pickingInfo object obtained from using pickWithRay method, now I want to simulate left mouse button click from inside the game which will be seen in onPointerObservable

I need it to reflect the move of one player in second player’s game and vice versa.

I would be very grateful for your help

Welcome to the forums!

I think what you’re looking for are the various Simulatepointer methods.

HTH

3 Likes

I came across this methods and tried to use the code below but with no effect, it is possible that I am misusing this method but it is undocumented and does not include examples, so I have a hard time telling if I am using it properly:

let hit = scene.pickWithRay(ray)
scene.simulatePointerDown(hit, {button: 0, buttons: 0, pointerType: “mouse”})

I want my simulate click to get inside this closure:

scene.onPointerObservable.add((pointerInfo) => {
switch (pointerInfo.type) {
case BABYLON.PointerEventTypes.POINTERTAP:
if(pointerInfo.event.button == 0){

We support three types of event simulations - PointerUp, pointerDown and PointerMove. PointerTap is actually simulated using PointerDown and PointerUp, so you will need to simulate both in order to use this specific pointer event type (without a pointermove in the middle)

https://www.babylonjs-playground.com/#LK14R9

2 Likes

RaananW your answer was all I needed.
Thank you both for you help, I appreciate it!

1 Like