Forum Discussion
motorsep
10 years agoStart Partner
[Gear VR] Gamepad controls script ?
I thought I saw a script with gamepad controls for player's movement, but now I question myself seeing it. Is there such a script for Unity in Utils or am I imagining things?
If I am imagining things :? could someone please explain how to add gamepad's analog thumb stick controls for player's movement (in addition to already existing WASD) ? I couldn't find any tutorials online about working with mobile gamepads :roll:
Thanks!
If I am imagining things :? could someone please explain how to add gamepad's analog thumb stick controls for player's movement (in addition to already existing WASD) ? I couldn't find any tutorials online about working with mobile gamepads :roll:
Thanks!
13 Replies
Replies have been turned off for this discussion
- kerskMeta EmployeeYou're not imagining things! :)
In the utilities package, there is an OVRPlayerController prefab and OVRPlayerController.cs script which demonstrate how to do this. Take a look in \Assets\OVR\Scripts\Util\OVRPlayerController.cs around line #320 for how the gamepad is used to control the player's movement.
On PC platforms, we've also added a new OVRInput class that makes this easier. You can get the left gamepad stick like this:Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
That is currently PC-only. We're going to support Android with the same OVRInput class in an upcoming Utilities release, but for now you can use the older way like this on Android:float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);
Also, on Android, you should make sure your Unity input bindings are setup in the "Edit -> Project Settings -> Input" window. The easiest way to do that is to just use the InputManager.asset file that comes with the Utilities package. To use that -- close down Unity and then swap in our InputManager.asset that came with the Utilities package by replacing your current one found in <your project directory>\ProjectSettings\InputManager.asset.
Hope that helps! - motorsepStart PartnerI'll dig into it, thanks a bunch!
Can I use same older Android method on PC? (since I have the same gamepad connected through a bluetooth dongle) - motorsepStart PartnerI don't think that portion of the code works at all. I commented it out completely, and yet XBox360 gamepad works for movement and look around.
I noticed there is OVRGamepad(soemthing).cs in the Utils\ folder and it has bunch of structs with names mirroring what's in the Input preferences. I haven't dug into it yet, but compare to a few gamepad tutorials I managed to find online this is soooo over-complicated :/
I have Xbox360 gamepad and this thing: http://www.amazon.com/gp/product/B00UJC ... ge_o01_s00
After messing with Input preferences (I was just setting Joystick Axis X or Y everywhere), I managed to get the second gamepad working for turning camera left/right, but what I really needed was moving player.
Could you please tell me how that input system works and what Input parameters are responsible for moving player? (on Xbox360 gamepad it was left thumbstick)
Thanks. - motorsepStart PartnerProgress - I found and modified input settings that allowed me to use the bluetooth gamepad in the Editor:

Are those the correct ones? Or should I tweak something else?
Haven't tested on the phone yet.
I am also wondering about changing speed of movement as initial speed is too slow IMO. How do I do that? - AnonymousEasiest way is to drag the provided InputManager file from the SDK examples and drag it into your project (while it's not open)
Not clear why Unity doesn't just make it possible to assign a default inputMaster file just like I don't understand why you can't select your sig file and have it use it automatically.
Regarding speed control: You could set a public variable so you can change in the settings.
And then simply use that as a scale to the input depending on your actual motion code. - motorsepStart Partner
private float MoveScaleMultiplier = 1.0f;
Increasing this one did the trick, however, now the issue is that if I let go of gamepad, player still moves o.O (slowly drifting)
How can that be fixed ?
Another weird behavior is that one axis does what it suppose to do (on Android) - moves player forward and back. However another axis rotates the view, as if one axis is treated as LeftXAxis (or LeftYAxis), but second axis on the same thumb stick is treated as RightXAxis.
So basically same gamepad on PC works as expected, but on Android it works differently. How do I fix it ?
Thanks. - motorsepStart PartnerSo after digging into it, my guess is that dead zones are not even taken into consideration in the UpdateMovement(); (or UpdateMotion(); ? ) So any value > or < than zero on gamepad axis will be translated into player's movement. Is that a correct assessment ?
- motorsepStart PartnerSo, I finally figured it out. Basically Oculus Utils don't care for dead zone set in the Input manager and I am not sure how to access dead zone using OVRGamepadController.
I simply added deadzone variable and used that in UpdateMovement();public float GamepadDeadzone = 0.1f;
if (leftAxisY > 1.0f * GamepadDeadzone)
MoveThrottle += ort * (leftAxisY * transform.lossyScale.z * moveInfluence * Vector3.forward);
if (leftAxisY < -1.0f * GamepadDeadzone)
MoveThrottle += ort * (Mathf.Abs(leftAxisY) * transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
Question: Does this #if UNITY_ANDROID block of code mean that if the app is running on Android, the code is being utilized? Or does it mean that if current platform is Android, that code will run, even if it's in the Editor?
The reason I am asking is that when I press Play button in the Editor on PC, that particular code within #if UNITY_ANDROID block is utilized. - kerskMeta EmployeeIn the next 0.1.3.0 Utilities release due out in a few days, OVRInput.cs will add support for Android gamepads to help unify PC/Android input. The older OVRGamepadController.cs and OVRInputControl.cs scripts will still be included for now, but they will be deprecated and are planned to be removed in a future release. This update will also include deadzone handling, fix a few bugs, and will programmatically handle the InputManager.asset for Android so you won't need to fight against all these setup issues.
For how things currently work though, OVRGamepadController.cs on Android uses the "Left_X_Axis" and "Left_Y_Axis" axes in Unity's input manager, set to the X and Y axis enum, respectively. Verify that those axes are set correctly for you. If that's not working for your specific android gamepad, it may be using non-standard layout bindings and you may need to use a different axis to get it working.
As for the preprocessor question, "#if UNITY_ANDROID" will be defined/true in the Editor if the current build platform is set to Android. A common pattern is to do "#if UNITY_ANDROID && !UNITY_EDITOR" to isolate any code you want to run only on android devices and not in the editor. - motorsepStart Partner@kersk: Sounds like a plan!
I am guessing Windows and Android might have axes defined differently for the same gamepad (in the system's driver). Would that be a correct assessment?
Btw, could you guys please hook up Esc event (return button on Gear VR) to popping up dialog "Quit app?" <Yes>/<No> and quitting the app/game (going back to Oculus Store?) on <Yes> (going back to the app on <No>) ? That's for this upcoming release of the Utils.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 months ago
- 11 months ago
- 10 months ago