efroemling / ballistica

The BombSquad Game Engine
Other
522 stars 106 forks source link

Feature Request: Haptic Feedback (force feedback, rumble) #174

Open Areopagitics opened 4 years ago

Areopagitics commented 4 years ago

Hi Eric,

Your game would be great with force feedback. I lfound that sdl2, the one you are using, has force feedback.

https://wiki.libsdl.org/CategoryForceFeedback

Let me know if I could help in some way. I have a bit of experience with python, not too much with C++ but wouldn't mind getting my hands a bit dirty ... would love to help if it's not too complicated.

Areopagitics commented 3 years ago

It looks like you would just need to call SDL_HapticRumbleSupported on the controller to check if it has rumble (when it connects), and then SDL_HapticRumblePlay triggered by events (for example when receiving punches, bombs, or snowballs).

efroemling commented 3 years ago

I would be all for adding something like this, though its low on my priority list at the moment. If anyone wants to help out, the first step would be adding some sort of haptic events to the InputDevice class (perhaps virtual functions that by default do nothing). Then the Joystick class could override those to talk to SDL's functionality as you mention above. One could test it by simply having joysticks rumble when buttons are pressed on them/etc. but after that we would want to wire it up to be controlled by game events coming from the python layer.

ritiek commented 3 years ago

Interesting. Let me see if I can help you get this to work!

Areopagitics commented 3 years ago

@ritiek let me know if I can do any testing. I have both USB and Bluetooth controllers with vibration.

ritiek commented 3 years ago

@Areopagitics Thanks! I only have a Dualshock 4 controller which can be used both as wired and wireless. It'd be nice to see what happens with other controllers too.

I made a very experimental change on my fork in ritiek/ballistica@joystick-rumble-support. The controller should vibrate a little whenever you press the punch button in-game.

Areopagitics commented 3 years ago

sweet! I'll do a pull of your fork and try building on my Windows for the first time soon. I finally found the instructions ; they're great.

Areopagitics commented 3 years ago

@ritiek I'm guessing I would need to do a full clean build from source. I tried your repo using the prefab command for windows; I was able to build it with some errors and then run, but no luck getting the rumble to work. I tested the rumble on USB controller configuration settings though, and it's working fine.

Any suggestions on how to build your repo on a WSL 2 setup on windows?

SyedAhkam commented 5 months ago

Hey, whats the status on this? I'd love to help out since this feature sounds quite fun to implement.

I do have a DS4 lying around as well.

@ritiek @Areopagitics

ritiek commented 5 months ago

Hi @SyedAhkam.

I ported my above mentioned changes from 2020 to the latest version of the game as of few months ago. This should be a good starting point: ritiek/ballistica@game-controller-rumbling (should rumble when you press punch button on the controller)

I remember it working fine on my Linux machine. Don't have Windows around to test with, so not sure if or how to get these changes working on Windows.

Ideally in the actual game, I feel it should rumble on say when our punch actually lands on the opponent (not just on pressing the punch button, which is what I did in my branch up), or when our character gets punched, or there's a bomb detonating somewhere. So someone will have to research where all in the codebase should we be adding these rumble calls. It'd also be nice to make sure this rumble behaviour works the same way during online play.