This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I want to use gyroaim like in FPS games at Nintendo Switch on consoles and mouse on PC for controlling aim point.

How to do it?

in Engine by (275 points)

Godot handles accelerometer input differently than mouse input. Here is the docs section for retrieving a value from accelerometers. The docs are your friend.

The docs clearly state that this method only works on iOS, Android and UWP, so this doesn't answer the question. I'm also searching for this andhave foundo no way so far for godot to recognize the dual shock 4 gyro.

1 Answer

+1 vote

I know this is an old question, but thought I'd give some info that I found while trying to do the same. As far as I can tell, there is no way to retrieve gyro input from controllers in the godot engine itself, unless the gyro input is miraculously being read into one of the joy axes (which seems pretty unreliable).

To get around this, then, you need to implement reading data from external devices yourself, which is something that I think is impossible in GDScript. So there's two options left, c++ or c#. From the two, c# is probably easier since godot natively supports it, though I think it wouldn't be much harder using c++. The top answer from https://gamedev.stackexchange.com/questions/87106/accessing-dualshock-4-motion-sensor-in-windows-ideally-unity is a good guideline on what you should do, but I'll go into more detail if you're looking at only deploying to windows platforms.

You should grab code from the ds4windows github page, specifically the files in HidLibrary. In some script of your own, you should then call HidDevices.enumerate() and find the controller from these returned devices, say named gyrocontroller. You should then call gryocontroller.OpenDevice(false) to setup your controller to be read from. In _process, call gyrocontroller.ReadFile(inputReport), where inputReport is some 64 byte array defined in your script. inputReport will now be filled the most current input from your controller, which will contain gyro info. To find which bytes are relevant to gyro data is dependent on the type of controller and how it's connected to your computer, but there are references online that cover that.

by (16 points)

I will use C++ through GDNative.

Maybe it is possible to use source code of this projects:
https://github.com/JibbSmart/JoyShockMapper
https://github.com/Davidobot/BetterJoy

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.