Is there a way to distinguish clicking (down/up) and click-and-drag (down/drag/up) in BabylonJS?
I tried this java script code here but to no avail so far.
// Distinguish click / click drag
let drag = false;
document.addEventListener(
'mousedown', () => drag = false);
document.addEventListener(
'mousemove', () => drag = true);
document.addEventListener(
'mouseup', () => console.log(
drag ? 'drag' : 'click'));
In the doc I see “onPointerDown” and “onPointerUp” but no indication on how to distinguish both techniques.
Thanks!
The way we do it is slightly delay registering the click and see if there is any dragging going on. If there has been, skip the click.
@br-matt thank you for the pointer. We ended up using camera position and rotation difference between mouse down and mouse up. Works like a charm!
alFrame:
Is there a way to distinguish clicking (down/up) and click-and-drag (down/drag/up) in BabylonJS?
I tried this java script code here but to no avail so far.
// Distinguish click / click drag
let drag = false;
document.addEventListener(
'mousedown', () => drag = false);
document.addEventListener(
'mousemove', () => drag = true);
document.addEventListener(
'mouseup', () => console.log(
drag ? 'drag' : 'click'));
In the doc I see “onPointerDown” and “onPointerUp” but no indication on how to distinguish both techniques.
Thanks!
Yes, BabylonJS has an event listener that can distinguish between clicking and click-and-drag , called “onPointerDown” and “onPointerUp”. This allows you to detect whether the user is performing a click or a click-and-drag action with their mouse.