Skip to content

Mouse wheel is too fast in wasm builds: unit Pixel vs Line confusion #21140

@strowk

Description

@strowk

Bevy version and features

[dependencies.bevy]
version = "0.16.1"

Relevant system information

I made two builds - one for Windows 11 and one for wasm, which I use with Edge.

What you did

I was trying to work out how to zoom out camera. Here is the system that reproduces the issue:

fn zoom_camera(
    mut scroll_evr: EventReader<MouseWheel>,
    camera_query: Single<&mut Projection, With<Camera2d>>,
) {
    match *camera_query.into_inner() {
        Projection::Orthographic(ref mut orthographic) => {
            for event in scroll_evr.read() {
                info!("Mouse wheel: {event:?}");
                //Adding to scale zooms out (the -= is there since it is reversed -> adding to scale zooms out)
                orthographic.scale = (orthographic.scale - event.y * 0.03).clamp(0.1, 3.0);
            }
        }
        _ => (),
    }
}

Note the log info!("Mouse wheel: {event:?}");

What went wrong

Moving mouse wheel on windows build and on web build results in two very different changes and two different logs. Web build produces much bigger change for some reason.

Here is log from browser (after one minimal wheel rotation):

Mouse wheel: MouseWheel { unit: Pixel, x: 0.0, y: 100.0, window: 0v1#4294967296 }

and same for Windows build:

 Mouse wheel: MouseWheel { unit: Line, x: 0.0, y: 1.0, window: 0v1#4294967296 }

As you can see the change in "y" is 100 times different!

Additional information

Nothing I could find so far.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreC-BugAn unexpected or incorrect behaviorC-DocsAn addition or correction to our documentationO-WebSpecific to web (WASM) buildsS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions