godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.06k stars 65 forks source link

Add support for force feedback in steering wheels #8309

Open x-channel opened 7 months ago

x-channel commented 7 months ago

Describe the project you are working on

I'm start to project game where you travel in Pernambuco's countryside.

I already write godot flavor with force feedback. It work on windows and linux, with respective direct input 8 and ioctl for linux. I published branch and example on itch.io. 6 people downloaded it.

https://cairerocha.itch.io/godot-force-feedback-example-ffb

Describe the problem or limitation you are having in your project

The game engine can't apply force in logitech G29 device.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add input methods to apply force, like rumble in xbox controller.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

func _on_ConstantForce_pressed():
    Input.constant_force_feedback(deviceID, force * direction, duration)

# cw is clock-wise coefficient, ccw is counter clock-wise
func _on_Spring_pressed():
    Input.spring_force_feedback(deviceID, cw, ccw, offset, duration)

func _on_Friction_pressed():
    Input.friction_force_feedback(deviceID, cw, ccw, duration)

func _on_Damper_pressed():
    Input.damper_force_feedback(deviceID, cw, ccw, offset, duration)

func _on_Inertia_pressed():
    Input.inertia_force_feedback(deviceID, cw, ccw, offset, duration)

func _on_Stop_pressed():
    Input.stop_force_feedback(deviceID)

If this enhancement will not be used often, can it be worked around with a few lines of script?

Dechode already tried it, but there several issues in this approach.

Dechode / Godot-FFB-SDL

Is there a reason why this should be core and not an add-on in the asset library?

There will be nice if someone can run it as add-on, but gdscript can't acess this.

Calinou commented 7 months ago

I support this in principle, but I have similar concerns as https://github.com/godotengine/godot-proposals/issues/2829. Is it possible to reasonably support the majority of steering wheels out there without needing lots of maintenance work on our end, considering there are no plans to use SDL in its entirety? This requires OS-specific code after all, as evidenced by your use of DirectInput and ioctl.

It has been discussed that we could copy SDL's input code where relevant and using it in Godot to support things like https://github.com/godotengine/godot-proposals/issues/2829, but this is still challenging to do (and keep up-to-date with newer SDL versions).

Edit: Using SDL only for input could also be an option.

x-channel commented 7 months ago

@Calinou thanks to answer. Both ioctl and DirectInput is out of date, with bad documentation, that bring some technical deficit. I will study more about SDL2 to copy code and continue feeding my branch. Who need this feature could just download it.

berarma commented 2 weeks ago

@x-channel What do you mean by "ioctl is out of date"?

On Linux, ioctl is the generic interface every supported wheel uses. No need to use SDL. SDL acts just as a wrapper for ioctl. I see we're already using ioctl for the rumble effect in gamepads, so it would only need to be extended for more effects.

I don't know about Windows. DirectInput provides generic FFB support but I don't know if it's really out of date. Many games still use it so I'm not sure if it's out of date or it's just not the newest API. I quick look at UWP and it seems that generic FFB it's included.

I don't think SDL is needed for this, the same way it wasn't needed for vibration in gamepads.

Calinou commented 1 week ago

I don't think SDL is needed for this, the same way it wasn't needed for vibration in gamepads.

It looks like we may be switching to SDL for input in the long run anyway, since it fixes a lot of issues with gamepads: https://github.com/godotengine/godot/pull/87925