godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
87.34k stars 19.62k forks source link

Vibration doesn't work for some controllers #14634

Closed toby3d closed 5 months ago

toby3d commented 6 years ago

Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Operating system or device, Godot version, GPU Model and driver (if graphics related): 1c0007b commit from master branch, Linux Mint Mate 18.2 x86_64 Issue description: (for example) Input.start_joy_vibration(0, 0.5, 1, 5) don't do anything. Tested with connected PS, XBox and Steam Constrollers.

Bugsquad edit (keywords for easier searching): vibrate, gamepad, joystick

vnen commented 6 years ago

Works for me on Windows 10, with an Xbox 360 controller. Might be Linux only.

toby3d commented 6 years ago

The controllers are successfully connected, the control works without unnecessary movements. Vibration works on Steam, but not in Godot.

akien-mga commented 6 years ago

Tested on Mageia 6 x86_64 (Linux) with the same commit and my two controllers work fine:

brainsick commented 6 years ago

Ubuntu 17.10 x86_64 Microsoft X-Box One Pad Godot 2.1.4 (Steam) and Godot 3.0 Beta 1 Joypads Demo - Start Vibration ... works for me

toby3d commented 6 years ago

Hm... I try check demo project little later, maybe I just use method not right.

toby3d commented 6 years ago

Okay, only Steam Controller via SC Controller app works with vibration. Others - worked and finded by godot app, but vibration doesn't work.

akien-mga commented 6 years ago

We have now entered release freeze for Godot 3.0 and want to focus only on release critical issues for that milestone. Therefore, we're moving this issue to the 3.1 milestone, though a fix may be made available for a 3.0.x maintenance release after it has been tested in the master branch during 3.1 development. If you consider that this issue is critical enough to warrant blocking the 3.0 release until fixed, please comment so that we can assess it more in-depth.

akien-mga commented 5 years ago

We need more information on what exact controller models and setup do not work, as so far nobody could reproduce those issues.

ghost commented 4 years ago

I am here to bring an exact setup for my controller. I am using MacOS Mojave 10.14.6 with a Dualshock PS4 Controller I bought at Walmart.

The controller vibrates when told to by Steam (Identify Controller Feature). The model number of the controller is CUH-2CT2U. It is an official Sony controller.

Using the System Information app on my Mac, I found this info (Bluetooth).

PS4 Controller:
  Address:  90-89-5F-B8-64-E5
  Major Type:   Peripheral
  Minor Type:   Peripheral
  Services: Wireless Controller
  Paired:   Yes
  Configured:   Yes
  Connected:    Yes
  Manufacturer: Unknown (0x7, 0x00)
  Firmware Version: 0x0100
  Vendor ID:    0x054C
  Product ID:   0x09CC
  Class of Device:  0x05 0x02 0x2508
  AFH:  On
  AFH Map:  F0F719000370807D
  RSSI: -42
  Role: Master
  Connection Mode:  Active Mode
  Interval: 0 ms
  Host Connectable: No
  EDR Supported:    Yes
  eSCO Supported:   Yes
  SSP Supported:    Yes
ghost commented 4 years ago

@akien-mga

Not getting vibration from PS4 controllers on Windows builds. Checked and still present in 318c69351.

I have had this issue for as long as I have been using Godot. Reluctant to report, since it seems like there are no longer active contributors for this area of the engine.

So the following line does nothing for me, but will work if I use an emulator to emulate an XBox controller.

Input.start_joy_vibration(0, 1.0, 1.0, 1.0)

My details are:

Win10 64-bit Joypad - Sony DualShock 4 GUID - 4c05cc09000000000000504944564944

follower commented 4 years ago

Note that--on Windows--vibration relies on the XInput API which the official docs describe as "allows applications to receive input from the Xbox Controller for Windows"--i.e. at least officially, it's not a generic controller API.

I notice that SDL haptic support includes XInput & DirectX Input support on Windows, so adding additional controller support via DirectX may be possible.

Related issue: https://github.com/godotengine/godot/issues/30256

Related links:

Lunatoid commented 3 years ago

At least for Windows, controllers need to be emulated as an XInput device. I tested with my DualShock 4 controller on Windows 10 and it didn't work, however when I used DS4Windows, which turns your DS4 into an emulated Xbox controller, it did work.

DS4Windows seems to use the ViGEmBus driver for it's emulation, perhaps that could be a place to look.

wingeisoftware commented 3 years ago

For the record, I just ran into a "Vibration not working issue". My controller was plugged via a (cheap) usb hub, and that was the issue. I soon as i connected my gamepad directly to the computer it worked. I guess the hub did not deliver enough power for the vibration motors.

djrain commented 3 years ago

Vibration is not working for me using Xbox Series X controller, on macOS Big Sur over bluetooth. The vibration works using this website https://gamepad-tester.com/ but not in Godot (3.3.2 stable)

trevorparscal commented 2 years ago

It's also not working for my 8bitdo SM30 Pro+ (which emulates a Sony PS4 Dualshock) under macOS Monterey, and that same website works perfectly for me as well.

umutseven92 commented 2 years ago

macOS Monterey 12.1, Macbook Pro M1 Max, Xbox One Controller over Bluetooth, Godot 3.4.2. Input.start_joy_vibration does not work. Same as the commenter above, vibration works when tested via gamepad-tester.com.

jeudy-ua commented 2 years ago

For me, it works on a cheap USB controller on Ubuntu 21.10, but on Windows 10, same machine and controller, it doesn't work. Using version 3.3-stable.

Stroopwafe1 commented 2 years ago

Same issue for me on Garuda Linux on kernal version 5.17.5-zen1-1-zen. Official controllers seem to work but my PDP Wired Controller for Xbox Series X - Black Camo doesn't seem to want to vibrate. It works fine on Windows so I imagine it's a drivers issue with my controller not being officially supported yet. I added the SDL mapping to the input of our game, because the axes were mapped differently, but the vibration is done by something else I imagine...

brettchalupa commented 1 year ago

Is this issue up for grabs still? I'm interested in taking on trying to fix it. I've got a PS4 controller, Switch controller, and an Xbox One controller with access to Linux, macOS, and Windows. I'd be happy to dig into this and get it as cross-platform and cross-controller as possible.

Rubonnek commented 1 year ago

@brettchalupa It's up for grabs. I don't think anyone else is working on this.

brettchalupa commented 1 year ago

I've been doing some testing on Ubuntu, Steam Deck, and macOS today with a little test app to detect controllers and rumble them. Here are my findings so far with Godot v4.0.rc2.official [d2699dc7a].

I haven't booted up Windows and tested that yet, but I am assuming Xbox (aka Xinput) works there.

My next steps are:

If anyone else is interested in lending a hand with testing or investigating, let me know! It'd be much appreciated.

HaSa1002 commented 1 year ago

On Windows, you'll find only XInput to be working. All other controllers need directinput that is not implemented. Switch Pro controllers only work using Steam Input when connected via cable. Bluetooth seems to be working though. I dunno what they do to make that work (Windows only reads information spam). SDL has some info how to trigger vibrations on DualShock and DualSense as well as an example how to use the adaptive triggers. Maybe you'll find some pointers there.

brettchalupa commented 1 year ago

@HaSa1002 Thanks, that's some helpful guidance and direction. 👍

brettchalupa commented 1 year ago

Let me know if I'm being too noisy here, but I thought I'd share some findings from the world of macOS rumble.

I tested some Unity games that I know have rumble support and none of them worked on macOS. So I dug into Apple's haptics API and can confirm it rumbles DS4 and XInput controllers with this sample game they provided. So at the very baseline, we know that with Swift and Apple's SDK, you can rumble a DS4 and Xbox One controller on macOS 12.6.

Then I thought, okay, let's see if SDL2 can rumble controllers on macOS. I wrote a little SDL2 CLI tester and tested some controllers. The controllers using XInput rumbled, awesome! And a controller that emulates Switch Pro Controller rumbled too, just a bit weakly. DS4/MFi and DirectInput controllers didn't rumble though, and SDL reports them as not supporting rumble.

So what does this mean? Well, it should at least be possible to get XInput controllers rumbling on macOS in Godot by referencing SDL's implementation. That's my initial goal, that way XInput controllers work on macOS, Windows, and Linux.

From there, outstanding questions are:

But I think XInput on modern macOS probably seems like a fine starting place for now for making this a bit better.

All right, time to dig into the Godot source. 😸

Calinou commented 1 year ago

How do we get DS4 (and maybe Dual Sense?) controllers working with rumble (and maybe the triggers too)? This seems like an interesting resource: JibbSmart/JoyShockLibrary

See discussion on https://github.com/godotengine/godot-proposals/issues/2829. JoyShockLibrary is in maintenance mode and may not remain maintained in the long term, but we don't want to adopt the entirety of SDL for binary size reasons (among other concerns). Copy-pasting code from relevant libraries is fine still.

brettchalupa commented 1 year ago

I’ve continued my research and testing to better understand what’s possible and what is and isn’t working. Here are some more findings:

In summary: rumble for XInput on MacOS and DualShock 4 on Windows are my highest priorities.

Need to test Deck, iOS, and Android more. Chrome web may be possible. It’s unclear how possible DS4 on MacOS will be, needs more experimentation. I don’t have a Dual Sense controller yet, but I’d like to eventually test and support that too.

A lot of what I’ve shared is just confirming the issues reported above, but it helps me to test the issues and have a couple control groups to test against like the SDL tester and a Unity game I know rumbles. I have a pretty good grasp on what’s possible and what to do next. Will try to report back in the coming days and hopefully have a PR.

brettchalupa commented 1 year ago

I've been digging into the Godot MacOS joypad vibration code and have some options for the path forward. Feedback and guidance would be much appreciated!

Current Godot MacOS Joypad Vibration Implementation

Right now the Godot Joypad implementation on MacOS uses Apple's ForceFeedback API. See the headers and vibration code. The ForceFeedback API has been supported in MacOS since 10.2, released back in 2003. It's not clear to me what devices this rumbles, but we do know it doesn't work for modern game controllers.

Godot also uses the MacOS IOKit API for interfacing with joypads.

MacOS Controller Paths Forward

Here are the options I see:

  1. Use the MacOS GameController system framework — this is Apple's robust controller API for interacting with modern controllers in all sorts of ways, including vibration/haptics. This is what Godot's iOS Joypad implementation uses.
    • Compatibility: iOS 7.0+, iPadOS 7.0+, macOS 10.9+, Mac Catalyst 13.0+, tvOS 9.0+
    • Would be implemented in Obj-C++, like iOS Joypad
    • Pros:
      • Will work with Xbox One, PS4, etc. controllers.
      • System API
      • Similar and/or shared implementation with Godot's iOS Joypad
      • It will be straightforward to get vibration working on iOS as a follow up
    • Cons:
      • Would require a re-implementation of the current MacOS joypad implementation, can't just add in a rumble support.
      • Might mean dropping support for MacOS joypad support for prior operating systems prior to macOS 10.9 (2013 release), unless there's a desire to maintain the current joypad implementation for those older operating system versions.
  2. Use the HIDAPI library — HIDAPI is a liberally licensed Human Interface Device (HID) library for interfacing with a variety of controllers. This is used by SDL, and it seems to work quite well for wide compatibility.
    • Pros:
      • Mature, stable library that's been widely used
      • Could help enable more than XInput rumble on Windows?
    • Cons:
      • Pulling in an entire library. Would Godot just use it for MacOS or for everything?
      • Requires a re-implementation without any reference within Godot

My Thoughts

I am honestly not sure... HIDAPI seems like it could unlock DualShock 4 rumble on Windows but would require a lot of work. More than I am likely capable of taking on. Going with the Apple GameController framework seems approachable because of Godot's iOS joypad implementation I can reference. It's also appealing to use a system API that can be shared across Apple platforms.

Next Steps

I'm not an expert in this domain. I'm just a person who wants my controller to rumble and am willing to do the work to help make that happen. 😂 I may be missing an option for a path forward.

Are any contributors/maintainers able to give me some guidance on how to proceed with this work or conversation? The scope of the decision seems too big for me to just make and start hacking away at the implementation without guidance/feedback.

Calinou commented 1 year ago

Might mean dropping support for MacOS joypad support for prior operating systems prior to macOS 10.9 (2013 release), unless there's a desire to maintain the current joypad implementation for those older operating system versions.

Godot 4 requires macOS 10.12 or later, so that's fine.

brettchalupa commented 1 year ago

Given I haven't gotten much feedback on my comment above, I'll plan on proceeding with the proposed option 1, Use the MacOS GameController system framework for getting MacOS vibration working. After sitting with this and learning more Godot over the past month, I think it's a good long-term solution.

Once that's done, I'd like to explore vibration on iOS, Android, Chrome web, and DualShock 4 on Windows after that. Help/support with DS4 on Windows would be welcome, as it's quite a different implementation than what exists.

Just to set expectations, it may be a few weeks/months before I have time to do this. But it's on my radar and important to me as I develop primarily on MacOS and want to add and test rumble in my games.

27thLiz commented 1 year ago

that should be fine, provided you can keep compatibility with the existing gamepad mappings

brettchalupa commented 1 year ago

Sorry for such silence here on this issue. I sadly no longer have a macOS machine due to a job change and am not able to really dig into the issue of getting rumble working on modern macOS. I hope that my findings that I shared above at least help someone pick this up with a little bit of context and info. Consider this issue unassigned and free to pick up for anyone who is interested in attempting to fix it. :+1:

Kryptyk1 commented 11 months ago

14634 #30256

Controller Vibration Not Working Using Either Setup:

Input.start_joy_vibration(1, 1.0, 1.0, 1.0)
Input.start_joy_vibration(0, 1.0, 1.0, 1.0)

On Godot v4.0.3.stable.official [5222a99f5]

With These Specs: OS Name Microsoft Windows 10 Home Version 10.0.19045 Build 19045 Other OS Description Not Available OS Manufacturer Microsoft Corporation System Name ####### System Manufacturer LENOVO System Model 81FB System Type x64-based PC System SKU LENOVO_MT_81FB_BU_idea_FM_ideapad 330S-15ARR Processor AMD Ryzen 3 2200U with Radeon Vega Mobile Gfx, 2500 Mhz, 2 Core(s), 4 Logical Processor(s) BIOS Version/Date LENOVO 7WCN38WW, 4/11/2019 SMBIOS Version 3.1 Embedded Controller Version 1.38 BIOS Mode UEFI BaseBoard Manufacturer LENOVO BaseBoard Product LNVNB161216 BaseBoard Version SDK0J40700WIN Platform Role Mobile Secure Boot State On PCR7 Configuration Elevation Required to View Windows Directory C:\WINDOWS System Directory C:\WINDOWS\system32 Boot Device \Device\HarddiskVolume1 Locale United States Hardware Abstraction Layer Version = "10.0.19041.2728" User Name ####### Time Zone ####### Installed Physical Memory (RAM) 8.00 GB Total Physical Memory 6.89 GB Available Physical Memory 2.06 GB Total Virtual Memory 13.8 GB Available Virtual Memory 7.03 GB Page File Space 6.89 GB Page File C:\pagefile.sys Kernel DMA Protection Off Virtualization-based security Not enabled Device Encryption Support Elevation Required to View Hyper-V - VM Monitor Mode Extensions Yes Hyper-V - Second Level Address Translation Extensions Yes Hyper-V - Virtualization Enabled in Firmware Yes Hyper-V - Data Execution Protection Yes

(Some Irrelevant personal info omitted)

With This PS4 Controller Model: MODEL CUH-ZCT2E

This was tested in Debug mode not in a build of the game.

p.s Sorry if I formatted/ referenced issues etc wrongly I am new to github.

JezerM commented 11 months ago

Hi, I just noticed that vibration doesn't work for controllers in macOS a few days ago, so I tried to fix it. I would appreciate if someone interested could test it.

And thanks to @brettchalupa for the initial guide on how controllers work in Godot and how this issue could be addressed.

coelhucas commented 7 months ago

Tested on MacOS with Xbox Series S gamepad, dualshock 4 and joycons, none working (as of version 4.1.3).

Alex2782 commented 7 months ago

@coelhucas There is already PR, I was able to test my Bluetooth XBox controller on Macos. https://github.com/godotengine/godot/pull/80709

JezerM commented 5 months ago

For macOS, this is already fixed in the master branch~

akien-mga commented 5 months ago

After https://github.com/godotengine/godot/pull/80709, I think we can close this old issue.

If anyone still experiences non-working vibration with some controllers on some platforms in 4.3 or later, please open a dedicated issue for that controller / platform combination so it can be assessed.

Yurinka commented 3 weeks ago

The issue continues happening in v4.2.2.stable.official when running it (reproduced it in the editor, using Windows 10):

-Xbox compatible gamepads rumble properly -DualShock4 (connected via USB) doesn't rumble -DualSense (connected via USB) doesn't rumble -Switch Pro controller doesn't rumble