Can I get velocity of gamepad like InputEventMouseMotion and get_velocity?()

Godot Version

4.2.1

Question

I want to make something to happen when you move the right thumb stick of gamepad quickly to the side to side.
I implemented it for mouse like codes the below, is there any way to convert it for gamepad or roundabout?

	if event is InputEventMouseMotion && picked_object:
		if abs(event.get_velocity().x) > 4000:
			something = true
		else:
			something = false

It would be nice.

But you could simulate it. Just have to take an axis save the value and on the next input event calculate a velocity based on the distance on that axis.

Var last_axis_val: float = 0.0 #or deadzone?
Func _inpt(event):
  If event is inputeventjopadmotion:
    If event.axis == JoyAxis.x_axis_whatever:
       If abs(last_axis_val - event.axis_val) > some_thresh:
          Do thing
       Last_axis_val = event.axis_val

...

The Axis goes from -1 to 1 so the “velocity” is the absolute difference between the two. You will have a maximum value of 2.

Comparing to mouse motion where you have 4000 pixels ( I assume) as your threshold. We have to understand the poll rate of Godot’s mouse logic to map to axis speed…

I guess trial and error would be easier :sweat_smile: you probably need to save a time stamp to help here as well. Or just assume controller poll rate is same as mouse poll rate.

1 Like

thank you! I gon try :slight_smile: happy new year <3

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