+3 votes

How do I get input from the mouse wheel? For example, for zooming in an out of the map in a strategy game.

The "Wheel Up Button" in Input doesn't seem to work, unfortunately. My mouse scrolls smoothly with no buttons. I think what I need is an analog input rather than an on/off value.

I'm using Godot 3.0.5 and C# but it should be roughly the same for GDscript.

in Engine by (103 points)
edited by

3 Answers

+4 votes
Best answer

This is the way to capture wheel mouse in Godot from C#.

public override void _UnhandledInput(InputEvent @event){
    if (@event is InputEventMouseButton){
        InputEventMouseButton emb = (InputEventMouseButton)@event;
        if (emb.IsPressed()){
            if (emb.ButtonIndex == (int)ButtonList.WheelUp){
            if (emb.ButtonIndex == (int)ButtonList.WheelDown){
by (58 points)
selected by
+12 votes

I don't know about C#, but I have this GDScript code for zooming:

if event is InputEventMouseButton:
    if event.is_pressed():
        # zoom in
        if event.button_index == BUTTON_WHEEL_UP:
            zoom_pos = get_global_mouse_position()
            # call the zoom function
        # zoom out
        if event.button_index == BUTTON_WHEEL_DOWN:
            zoom_pos = get_global_mouse_position()
            # call the zoom function
by (476 points)
+5 votes

Or you could just use:if Input.is_action_just_released(your thing)(gdscript)
The Wheel Up Button only has a just released function.

by (24 points)

Thank you very much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.