- Home /
How do I use android bluetooth controller in unity?
I have a bluetooth controller for my android phone (specifically the VR Park controller) and I want to use this for a VR game on my android phone. Does anyone know how I would take the joystick input from this? I have played other unity games which used it such as Hardecode VR so I know it can be done, I just don't know how I would get the input from the controller joystick to make the player move.
Answer by daveleack · May 25, 2016 at 01:44 AM
Gosh darned thing ate my reply (actually it may be in a moderation queue, so apologies for double posting if that's the case).
I'm trying to do this right now. I have the stick working OK. By default the VR Park is in pointer mode. Hold "@" and press "c" to go to what the instruction video calls "VR" mode. In this mode the stick produces the correct up, down, left and right events to control the FPSCharacterController script. The top trigger button also seems to press "space" which means jump works.
What I can't figure out is what the lower trigger button does. In android it seems to press back, but KeyCode.Escape doesn't seem to evaluate to whatever it's sending, if indeed it sends anything at all.
Do let me know if you get any further than I have. I'm quite keen to get this working.
Edit: I got it! If you put it in mode "B" (press "@" and "B") the lower trigger becomes "Fire1" (It's possible that the keycode it produces is actually either left ctrl or mouse 0, "Fire1" being the input button that triggered and those being what I had set to that button).
Good luck!
Edit: One more thing, I have to have mobile input turned OFF to get this bugger to work. No idea why, but I can't get it to work at all with mobile input turned on.
Hello!
I have the same controller that you mentioned. $$anonymous$$y app is really simple, I have a 3D object in VR and I want to walk around it. In the @+C mode I can make it walk with the joystick, and I have the jump with the upper button. In any else mode, I have no functional action (just the clicking).
It will be really good, if I could make these two things in the @+C mode: - set the upper button to do the Fire1 clicking (I have a menu in the app, I just need to activate the buttons with a click - I can do it in @+D mode, but I don't want to switch between them just for that...) - set the lower button to take back to my $$anonymous$$enu Scene (it will be the same function for each other scene as well).
I think, it won't be a great deal, but I can't find any setup stuff for this controller. If you figured it out yet, thank you for helping me!
@Schalll Sorry, I gave up on the VR Park controller a while ago. I've moved on to using vRidge to make OSVR stuff that runs from a PC. You get significantly more graphical power and can use an XBox pad without a USB host cable.
Not a solution if you want to deploy android apps though.
Hope you crack it or get some help from somewhere.
how do you make walk with joystick could you help me? -Schall
I used this snippet to make my character walk.
float vertical = Input.GetAxis("Vertical");
float horizontal = Input.GetAxis("Horizontal");
float speed=10f;
if ($$anonymous$$athf.Abs(vertical)>0.01){
//move in the direction of the camera
transform.position = transform.position + Camera.main.transform.forward * vertical * speed* Time.deltaTime;
}
if ($$anonymous$$athf.Abs(horizontal)>0.01){
//strafe sideways
transform.position+= new Vector3(0,0,-horizontal * speed* Time.deltaTime);
}
In mode 'C', the lower button is actually a "Cancel". Add a 3D Text to the $$anonymous$$ainCamera and use code snippets like these to check if the controller buttons work. I'm using the same controller and I could find that in different modes different inputs were being triggered (like "Fire3","Submit" etc)
if(Input.GetAxis("Cancel")==1)
{
text$$anonymous$$esh.text="Cancel";
}
Also, if I change the Controller $$anonymous$$odes in-game, the controller doesn't seem to work. Will get back here if I find anything new :)
Answer by jons190 · Jan 17, 2017 at 02:46 PM
So a heads up. If anyone has downloaded the new 1.24 Realistic FPS prefab. it seem to work much better in Unity/vr and I can actually build to the Gear VR device and sort walk around. The button mapping is still wonky and I'm going to try the above fixes and see if it cleans it up. I get nothing out of the unity input manager and the right joystick still maps as (move joystick up to turn right, move joystick down to turn left. ) But it works now, where before it didn't so progress!!!!!!!
Answer by DiGiaCom-Tech · May 24, 2016 at 07:10 PM
@Allwood_Game_Dev ... I purchased ReWired (http://guavaman.com/projects/rewired/) as a controller solution for my games. Once you create your base mappings and re-wire your game the rest is easy.
If you are on a budget and can't purchase a solution then I would start with the Bluetooth controller manufacturer. They usually offer SDKs for the various development platforms that should get you up and running quickly.
Note also that the VR aspect of your game really has nothing to do with control input aspect ... so the same applies to to non-VR games as well.
Answer by vochcuyrk · Nov 14, 2016 at 07:37 AM
hi everyone, I connect the bluetooth joystick as the answer said, it works, but I have a little problem, when I see to north, if I want to go forward, I just put the joystick up and It works, but when I turn my head to see west (for example), if I want to go forward I have to put joystick left, because if I put joystick up, my character goes to my right not forward, does anyone know why? how can I fix it?, thanks to all to read this
I suspect what you want to do is find the character controller script that moves your player and do a little bit of maths on the control input.
When you apply the y axis motion of the stick and turn it into movement, you want to take into account the direction of the camera.
Now, this is pseudocode, won't compile, but should give you an idea what to do:
motion vector = camera.transform.forward * y axis value * speed
Exactly how well this approach works will depend on the controller script you're using, but it should get you started.
I am having this exact problem. I'm using RFPS prefab and can't get the controller maping to work. I can't get the controller to go where its looking and in VR mode (both cardboard/daydream and Oculus) the "look" joystick will switch to up and down is actually look right and left. (but works perfectly in Unity before porting to the phone) It is super frustrating as i am a fairly noob at C#. i have downloaded the rewired plugin (it gives you a two $$anonymous$$ute demo before it times out and talked a bit with the devs at endspace and they said rewired fixed their problem, but i still haven't figured out a solution to this yet. If you come across anything, let me know as I would love to hear about any potential solution....
Hello @vochcuyrk , Try the following:
You have add a variable to store our "head" In FirstPersonController script.
...
private Camera m_Camera;
public GameObject head;
private bool m_Jump;
...
Then find this line:
Vector3 desired$$anonymous$$ove = transform.forward m_Input.y + transform.right m_Input.x;
and change it to:
Vector3 desired$$anonymous$$ove = head.transform.forward * m_Input.y + head.transform.right*m_Input.x;
In Input$$anonymous$$anager it duplicates $$anonymous$$ouseX and $$anonymous$$ouseY, in addition you have to disable $$anonymous$$obileInput in the $$anonymous$$enu bar. Greetings from Peru
Hi, I did it like above. so if i did public GameObject head; i have to connect to the object in inspector. I did it like in added photo.
Result is like changed axis. I mean right joystick move forward, forward joystick to the left.
pls help.
Hello @olszelus5 . Do not forget :
To disable Input$$anonymous$$obile
Change the line of code in "FixedUpdate" function :
Vector3 desired$$anonymous$$ove = transform.forward * m_Input.y + transform.right * m_Input.x;
by
Vector3 desired$$anonymous$$ove = head.transform.forward * m_Input.y + head.transform.right*m_Input.x;
Finally In Input$$anonymous$$anager duplicate Axes for $$anonymous$$ouseX and $$anonymous$$ouseY with the same values as well as the image below.
I hope to be helpful.
Answer by Nep36 · Jan 10, 2017 at 07:34 AM
@daveleack Hi from France daveleack, thanks a lot for your post. I've follow your tips but I cant move the camera with the joystick. Ive got the same bt controller as you. On editor mode, keyboard works well for moving the character, did you used special settings in the input manager? Have u got an idea ? Thanks
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Unity android bluetooth controller disconnect doesn't make array empty 1 Answer
Using "Custom Bluetooth HID Device" on Android Unity Application. 0 Answers
Using a bluetooth gamepad controller with iOS/Android 1 Answer
How to detect on android if bluetooth controller disconnects? 0 Answers