I am experiencing some strange behaviors of the SDL2's Haptics methods. I have tested this under Linux 64bit with libsdl2-dev and libsdl2-2.0-0 (both in version v2.0.10) and Windows 10 64bit (latest SDL binary build). As controllers I used the 8Bitdo SF30 Pro Gamepad and a Nintendo Switch Pro Controller - both connected via USB.
SDL_HapticRumblePlay and SDL_HapticRunEffect are driving the rumble motor at a quite low frequency (I assume 2-5 Hz) with a resulting small magnitude. Any changes in the effect struct (such as wave-type, magnitute, directions, period, and so on..) do not show any improvements. It also seems that on each SDL_HapticRunEffect call, the vibrations vary a bit. The SDL_HapticsSetGain method does not seem to have any effect either.Do you have any suggestions on these behaviors?
Although not exactly the answer you might be looking for if you must use the SDL2 haptic methods for any reason, but this comment on a similar issue with haptics in SDL2 states the following:
For gamepads the haptic interfaces are deprecated in favor of SDL_GameControllerRumble(), which is implemented on more platforms for game controllers. The haptic API in general is moving towards just supporting wheels and flightsticks. (Aug. 2021)
So the answer to both of your questions may be that SDL2 haptics is deprecated for gamepads, especially newer ones like the Nintendo Pro Controller, and thus it cannot be guaranteed to work properly (or to work at all).
However, if you simply want to get your gamepad to rumble (which is why I stumbled across this question), using SDL_GameControllerRumble() should do the job. It worked for me with a Nintendo Pro Controller.
Have a look at the SDL_GameControllerRumble - SDL Wiki for more info on how to use it.
Required version to use this function is SDL 2.0.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With