Mouse sensivity in 2D

Godot Version

4.3

Question

I want to modify the mouse sensivity in a 2D scene, you see I have something like this to control a character body2D:

Player.position = event.global_position

so I want to give the player the option to modify the mouse sensivity, any idea of how can I achieve this?
Thank you for your time.

Maybe I’m saying something stupid but:

  1. Capture mouse movement: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED.
  2. Define a variable mouse_sensitivity:float.
  3. “Multiply”: event.global_position * mouse_sensitivity.

For example, to know the direction of movement entered, I think you could use something like:

func _input(event):
   if event is InputEventMouseButton:
	input_direction = - event.relative.x * mouse_sensitivity

I already tried that it’s the first thing that came to my mind but it doesn’t work obviously. The thing is that if you equal the sprite to the mouse position but you set mouse captured on godot then the sprite won’t move and multiplying by the mouse sensivity teleports the player because it modifies the coordinates of the mouse.
Anyways thank you for trying to help :slightly_smiling_face:

Yes, you can’t just teleport using the event.global_position unless you want it to be that way.
In a project I’m doing (3D) I use the input_direction that I put below. That gives you the direction where you should move the player based on their speed. I think that would be worth it to you.

I resolved the problem now, what I did was take a camera 3d approach, instead of controlling the mouse and making the player teleport to it I instead get the mouse motion values and I add them to the X and Y values of the screen. I got the idea from this article maybe it is useful to you too! :blush::

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.