Distinguish click/ click and drag

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.

3 Likes

@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!