Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Allwood_Game_Dev · Apr 04, 2016 at 07:29 AM · androidvrcontrollerjoystickbluetooth

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
6

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).

@Allwood_Game_Dev

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Schalll · Nov 01, 2016 at 06:22 PM 0
Share

Hello!

@daveleack

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!

avatar image daveleack Schalll · Nov 16, 2016 at 03:36 PM 0
Share

@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.

avatar image malisasmaz Schalll · Nov 29, 2016 at 08:25 AM 0
Share

how do you make walk with joystick could you help me? -Schall

avatar image UDN_b371e0c2-57b9-4491-abd4-3aef0e02ba5f malisasmaz · Jan 19, 2017 at 07:02 AM 2
Share

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);        
     }

avatar image UDN_b371e0c2-57b9-4491-abd4-3aef0e02ba5f Schalll · Jan 19, 2017 at 06:58 AM 1
Share

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 :)

avatar image
1

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!!!!!!!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image daveleack · Nov 16, 2016 at 12:16 PM 0
Share

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.

avatar image jons190 · Nov 22, 2016 at 12:02 AM 0
Share

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....

avatar image ArturoPaz · Jan 10, 2017 at 01:20 PM 0
Share

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

alt text

inputmanager.jpg (34.3 kB)
avatar image olszelu5 ArturoPaz · Jan 13, 2017 at 12:31 PM 0
Share

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.

alt text

1.jpg (149.3 kB)
avatar image ArturoPaz ArturoPaz · Jan 15, 2017 at 07:55 PM 0
Share

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.


alt text

alt text

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges