Support for gyro aiming? #112
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot#112
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Would it be possible to add support for gyro aiming controls from controllers that have motion features, like the DualSense? Currently, I can use the DualSense gyro controls on emulators just fine, but not on Hookshot
My 8BitDo Ultimate 2C also has gyro that can be used in emulators and does not work with the gyro aiming in Hookshot.
Even after the update that just came out I can confirm it still does not function.
Got this working (DualSense over USB, Ocarina of Time: Switch 2 Edition). Three things were needed:
1. SDL sensors. Enable them when a pad opens (
SDL_GameControllerSetSensorEnabledfor accel and gyro) and feed the states into the six-axis HLE: acceleration in m/s², gyro in rad/s. The SDL z axis points toward the player, so the game's gravity reading flips sign.2. The game folds the euler angles, the pitch rate and the acceleration into its aim's recenter — anything not body-relative and neutral gets cancelled, which is why naive six-axis delivery looks dead. The working state:
Rx(pitch)), integrated from the body-frame pitch rateThe body-frame rates come from an up-vector complementary filter:
uppredicted from the gyro (up + (ω×up)·dt, normalized), pulled toward the measured gravity whenever |a| is 0.65..1.35 g; the rates projected onto right/up/forward. That makes the hold orientation irrelevant — works with the pad held flat or vertical (portrait, face to the player; verified on both with a DualSense).3. The motion pipeline is gated by the handle count. The game asks
GetSixAxisSensorHandlesfor 2 handles, but its motion branch (JCMS) only runs when the returned count is ≥ 3 — returning 3 turns the whole path on.Patch against
1720815is ready — will clean it into a PR.Patch (against
1720815): https://gist.github.com/spluton/d4b175de0013e1cd0b5754efd18eeb87I ported @spluton's gyro patch by hand to the current source (VERSION
3601726, it no longer applies cleanly) and tested it on Linux. The controller is a GameSir T3 Pro in Switch Pro Controller mode. Gyro aiming works, with two fixes:1. Horizontal aim was ~6x too fast: wrong unit for the yaw rate.
The Switch reports angular velocity in turns per second. Yuzu-based emulators convert this way too: SDL's rad/s divided by 2π. The patch passes the yaw rate (
v[4]) straight from SDL, in rad/s, so horizontal aiming came out 2π times too fast.The vertical axis was fine, because it goes through the integrated pitch matrix, which is an angle in radians. So the fix only scales the horizontal rate:
With this, aiming feels the same as in Eden on the same controller. Eden applies no extra gyro scaling.
2. A sensitivity option.
This adds
motion_sens=<x>(0.05–5, default 1) tohookshot_options.ini. It is parsed inmotion_bind()next tomotion_axis_x/y/z, and it multiplies the angular velocity:Note:
motion_bind()re-reads the file every 0.5 s. In my test, though, changes only took effect after restarting the game.Default axis bindings (2, 3, 0) are correct for this controller. Thanks to @spluton for the patch!
Be super cool if one of their PRs made it. Aiming without gyro on a controller can feel painful, especially when I'm used to having it from the Ship port lol
Thanks for the idea. Feature requests are now collected in #1007, which lists this one with a link back here, so closing it in favour of that list (this is not a decision against the idea). The gyro patches posted here are linked from the list.
Update: the gyro patch, ported to v2.0.7 (source 9b541c9c). It's attached as one unified diff against the v2.0.7 AppImage's source:
hookshot-v2.0.7-gyro.patch.txt. It applies withpatch -p1fromusr/share/hookshot.I built it with the v2.0.7 AppImage on Linux (CachyOS, RTX 4070 Super) and tested it with a GameSir T3 Pro in Switch Pro Controller mode. Gyro aiming works with the same feel as Eden/Lichii.
What changed since my port in this thread:
SDL3 and SDL2. Controllers now go through
hos_sdl.c, so the sensor calls live there:hos_sdl_pad_sensors_on()usesSDL_SetGamepadSensorEnabledon SDL3 andSDL_GameControllerSetSensorEnabledon SDL2.hos_sdl_pad_sensor()usesSDL_GetGamepadSensorDataon SDL3 andSDL_GameControllerGetSensorDataon SDL2. It handles each version's return convention (bool vs 0 for success).pad_sdl.cenables the sensors when a pad opens. On each poll it reads the accelerometer and gyro from the first pad that has them, andhos_sdl_sensors()hands that data tonn_hid.c.nn_hid.cis unchanged from my earlier port:hsum *= 1/(2π));motion_sens=inhookshot_options.ini.In v2.0.7 that file is read from beside
bin/hookshot.Default axis bindings (2, 3, 0) are correct on this controller. Thanks again to @spluton for the original patch. It would be great to see this in an official build!
Port of the gyro patch to v2.0.11, gyro only, as a diff against the stock v2.0.11 source. (The v2.0.7 file mentioned above never got attached, so here it is inline.)
Based on @spluton's gist and the v2.0.7 port notes above, including the horizontal speed fix (the yaw rate in turns per second: SDL's rad/s over 2π). Changes from the gist:
hos_sdl.c, SDL3 and SDL2, looked up as optional: without them the game runs as before;rx_option); the default axes are the gist's (2, 3, 0);GetSensorFusionHandles/FinalizeSensorFusionare not redefined: v2.0.11 already has them.It applies with
patch -p1from the tools folder and builds with 0 failures. Tested on Windows 11 (RTX 5080): aiming works with the slingshot, bow, hookshot and first-person view.HOS_MOTION_DEBUG=1logs what goes to the game twice a second.hookshot-v2.0.11-gyro.patch
shame that gyro is not planned officially as its a core part of the modern zelda games. other then that it works in emulators
I am someone who knows nothing.
I asked ChatGPT to handle your source code, and it made the gyroscope work.
Thank you.
I am a free ChatGPT user.
and here we are with working Gyro implemented now all of a sudden! in latest build