evt.wheelDelta clarification

Hi,

I would love some clarifications on the wheelDelta, is it the same as the browser MouseEvent or is it something internal exclusively to PC?
Would there be the need to make some adjustments in order to attach the events or is it done automatically by the engine (both editor and API).

thanks.


Screenshot 2025-02-06 at 11.55.13

@KPal

So there is a difference so the window version gives you an actual delta value however due to browser differences the PlayCanvas one will snap to either 1 or -1 depending on direction

PlayCanvas MouseEvent class:

// deltaY is in a different range across different browsers. The only thing
// that is consistent is the sign of the value so snap to -1/+1.
if (event.type === 'wheel') {
    if (event.deltaY > 0) {
        this.wheelDelta = 1;
    } else if (event.deltaY < 0) {
        this.wheelDelta = -1;
    }
}

Thanks for the answer.

Maybe I wasn’t clear enough in the original question.

what i’d like to know if the engine is listening to the browsers mousewheel event which seems to be tagged as deprecated and not standard → Element: mousewheel event - Web APIs | MDN or is it listening to this one WheelEvent - Web APIs | MDN ? so it’s safer to use and won’t give future issues

No its listening on the ‘wheel’ event on the window

We have just wrapped it in our own event which is called ‘mousewheel’.

I hope that answers your question. :slight_smile:

See engine source: engine/src/platform/input/mouse.js at main · playcanvas/engine · GitHub