Skip to content

Conversation

@Nintorch
Copy link

@Nintorch Nintorch commented Jan 28, 2026

Partially addresses #11466
Follow-up to godotengine/godot#111679

The gyroscope calibration explanation was borrowed from https://github.com/JibbSmart/GamepadMotionHelpers?tab=readme-ov-file#gyro-calibration

TODO:

  • Accelerometer Z axis

@Nintorch
Copy link
Author

Thank you for your review, AThousandShips! I will be able to fix the text in the PR soon!

@Nintorch Nintorch force-pushed the joypad-motion-sensors branch from f2f997c to 0d68400 Compare January 28, 2026 11:04
Co-Authored-By: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@Nintorch Nintorch force-pushed the joypad-motion-sensors branch from 0d68400 to 8f5a6f0 Compare January 28, 2026 11:06
@skyace65 skyace65 added this to the 4.7 milestone Jan 29, 2026
@skyace65
Copy link
Contributor

Might be a bit before this gets merged since it's for 4.7

Comment on lines +164 to +165
That's because modern gyroscopes often need calibration. This is like how a weighing scale can need calibration to tell it what 'zero' is.
Like a weighing scale, a correctly calibrated gyroscope will give an accurate reading.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
That's because modern gyroscopes often need calibration. This is like how a weighing scale can need calibration to tell it what 'zero' is.
Like a weighing scale, a correctly calibrated gyroscope will give an accurate reading.
That's because modern gyroscopes often need calibration. This is like how a weighing scale can need calibration to tell it what "zero" is.
Like a weighing scale, only a correctly calibrated gyroscope will give an accurate reading.

Comment on lines +177 to +182
**Accelerometer** is a type of sensor that detects a device's acceleration in m/s²,
which, in simpler terms, means it can detect if the device (in our case, a controller) has been physically moved quickly.
For example, it can detect if the player quickly raises their controller, quickly moves it to the side,
or if the player is shaking the controller.
Note that, unfortunately, it does not **not** mean that the device will be able to detect precise movements that,
for example, can be used to replicate a VR controller's movement.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Accelerometer** is a type of sensor that detects a device's acceleration in m/s²,
which, in simpler terms, means it can detect if the device (in our case, a controller) has been physically moved quickly.
For example, it can detect if the player quickly raises their controller, quickly moves it to the side,
or if the player is shaking the controller.
Note that, unfortunately, it does not **not** mean that the device will be able to detect precise movements that,
for example, can be used to replicate a VR controller's movement.
**Accelerometer** is a type of sensor that detects a device's acceleration in m/s².
In simpler terms, this means it can detect if the device (in our case, a controller) has been physically moved quickly.
For example, it can detect if the player quickly raises their controller, quickly moves it to the side,
or if the player is shaking the controller.
Note that, unfortunately, it does not **not** mean that the device will be able to detect precise movements that can be used to replicate a VR controller's movement (for example).

Comment on lines +204 to +206
The following example prints the controller movement when it's being quickly moved by using its accelerometer:
(If you feel like this code is too sensitive or not sensitive enough for your controller's physical movement,
you can also tweak the values used here however you feel like!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following example prints the controller movement when it's being quickly moved by using its accelerometer:
(If you feel like this code is too sensitive or not sensitive enough for your controller's physical movement,
you can also tweak the values used here however you feel like!)
The following example prints the controller movement when it's being quickly moved by using its accelerometer.
If you feel like this code is too sensitive or not sensitive enough for your controller's physical movement,
you can also tweak the values used here however you feel like.

Comment on lines +210 to +247
var detect_accelerometer = true
func _ready():
# In this example we only use the first connected joypad (id 0).
if 0 not in Input.get_connected_joypads():
return
if not Input.has_joy_motion_sensors(0):
return
# We must enable the motion sensors before using them.
Input.set_joy_motion_sensors_enabled(0, true)
func _process(delta):
if Input.has_joy_motion_sensors(0):
accelerometer_example()
func accelerometer_example():
if not detect_accelerometer:
return
var acceleration = Input.get_joy_accelerometer(0) - Input.get_joy_gravity(0)
if acceleration.length() > 10:
if acceleration.x > 10:
print("Moved left")
elif acceleration.x < -10:
print("Moved right")
if acceleration.y < -10:
print("Moved up")
elif acceleration.y > 10:
print("Moved down")
# After detecting movement in one direction, the accelerometer sensor
# will briefly report movement in the opposite direction, even though the controller only moved once.
# So we need to ignore these reported values for a short amount of time.
detect_accelerometer = false
await get_tree().create_timer(0.5, false).timeout
detect_accelerometer = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use spaces for indentation in docs:

Suggested change
var detect_accelerometer = true
func _ready():
# In this example we only use the first connected joypad (id 0).
if 0 not in Input.get_connected_joypads():
return
if not Input.has_joy_motion_sensors(0):
return
# We must enable the motion sensors before using them.
Input.set_joy_motion_sensors_enabled(0, true)
func _process(delta):
if Input.has_joy_motion_sensors(0):
accelerometer_example()
func accelerometer_example():
if not detect_accelerometer:
return
var acceleration = Input.get_joy_accelerometer(0) - Input.get_joy_gravity(0)
if acceleration.length() > 10:
if acceleration.x > 10:
print("Moved left")
elif acceleration.x < -10:
print("Moved right")
if acceleration.y < -10:
print("Moved up")
elif acceleration.y > 10:
print("Moved down")
# After detecting movement in one direction, the accelerometer sensor
# will briefly report movement in the opposite direction, even though the controller only moved once.
# So we need to ignore these reported values for a short amount of time.
detect_accelerometer = false
await get_tree().create_timer(0.5, false).timeout
detect_accelerometer = true
var detect_accelerometer = true
func _ready():
# In this example we only use the first connected joypad (id 0).
if 0 not in Input.get_connected_joypads():
return
if not Input.has_joy_motion_sensors(0):
return
# We must enable the motion sensors before using them.
Input.set_joy_motion_sensors_enabled(0, true)
func _process(delta):
if Input.has_joy_motion_sensors(0):
accelerometer_example()
func accelerometer_example():
if not detect_accelerometer:
return
var acceleration = Input.get_joy_accelerometer(0) - Input.get_joy_gravity(0)
if acceleration.length() > 10:
if acceleration.x > 10:
print("Moved left")
elif acceleration.x < -10:
print("Moved right")
if acceleration.y < -10:
print("Moved up")
elif acceleration.y > 10:
print("Moved down")
# After detecting movement in one direction, the accelerometer sensor
# will briefly report movement in the opposite direction, even though the controller only moved once.
# So we need to ignore these reported values for a short amount of time.
detect_accelerometer = false
await get_tree().create_timer(0.5, false).timeout
detect_accelerometer = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants