-
-
Notifications
You must be signed in to change notification settings - Fork 23.8k
Add support for joypad motion sensors #111679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
d32bb26 to
891671d
Compare
|
I'll try to test and review this on macOS soon! I'm not a maintainer of course, but IMO it'd make sense to include the calibration methods as well. That way, this PR can function as a sort of all-encompassing "motion control API pack", if that makes sense. (Additionally/alternatively, it could be looked at from the perspective of, without being able to calibrate the sensors, how can we be confident the functions are working correctly?) |
891671d to
fe9c73a
Compare
fe9c73a to
bcac074
Compare
68d3714 to
f26b181
Compare
|
Should I try combining the calibration process methods into one |
core/input/input.cpp
Outdated
| if (!joy_motion.has(p_device)) { | ||
| return; | ||
| } | ||
| joy_motion[p_device].accelerometer = p_value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An event probably needs to be added for this.
(Should these events exist? Should they be made in this PR?)
core/input/input.cpp
Outdated
| if (!joy_motion.has(p_device)) { | ||
| return; | ||
| } | ||
| joy_motion[p_device].gyroscope = p_value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
bd46062 to
b84588a
Compare
|
Should this PR convert the values to degrees per second for gyroscope and g-force for accelerometer? See https://github.com/JibbSmart/GamepadMotionHelpers?tab=readme-ov-file#units , which was mentioned in the proposal: godotengine/godot-proposals#2829 EDIT: I found out that |
Hello and thanks for your awesome work @Nintorch! As a user of a dual sense edge on linux (I'm assuming that we are rare specimens), I just wanted to chime in and say that gyros work perfectly with steam input. I don't want to block this PR or anything, as I alluded this is a pretty niche problem, but I don't want you to jump to the wrong conclusions just in case. I can offer my help testing the PR if you want, just tell me what you need. |
Hello, thank you for letting me know! |
|
Oh yeah, I've renamed these |
|
Ok good news! It works perfectly for me. Using Arch linux + KDE. |
|
That's good to hear! :) |
b84588a to
9422c91
Compare
I noticed this as well, the movement looked inverted for me until I removed the negation from line 157. I wonder why it was added? User preference or buggy controller mapping? |
|
I removed the |
033b32b to
9b12057
Compare
This comment was marked as resolved.
This comment was marked as resolved.
9b12057 to
f368d61
Compare
|
I should probably state in the documentation that motion sensors is an experimental feature and its usage may change in the future based on the feedback. |
f368d61 to
7276d80
Compare
7276d80 to
ea31a07
Compare
I needed it to be inverted in earlier PRs that added gyro support, but you can safely remove the negation now. |
|
Although, if EDIT: they really are inverted compared to mobile device's orientation methods, I will need to fix that |
ea31a07 to
b1db95b
Compare

Closes godotengine/godot-proposals#2829
Partially supersedes #88590
Requires #111707 to be merged first
I decided to split my big SDL3 joypad features PR ( #107967 ) into several smaller PRs, starting with joypad motion sensors.
This PR adds the ability to get a joypad's motion sensors (accelerometer, gyroscope) data readings (and also a simulated gravity sensor from the accelerometer data). The reason the gravity sensor had to be simulated: libsdl-org/SDL#6555 (comment)
This PR also includes the methods to calibrate the motion sensors output. I'm not an expert in sensor calibration, so please let me know if this approach looks good enough :D
EDIT: If the gravity calculation proves to not be good enough, we can probably use https://github.com/JibbSmart/GamepadMotionHelpers (if it's better) instead in this PR or in a separate PR to not block this one
Gravity sensor calculation code was borrowed from here: https://developer.android.com/reference/android/hardware/SensorEvent#values
This PR was tested on Windows, but it should also work on Linux and macOS.
TODO:
InputEventJoypadGyroscopeandInputEventJoypadAccelerometer(for a separate PR)Input.get_joy_sensor_rate()?has_joy_*,set_joy_*_enabledandis_joy_*_enabledas experimental (we may or may not need to only enable/disable the motion sensors together in the future, I think)Test project (doesn't include the calibration yet):
joypad-motion-sensors.zip