Forum Discussion
Caine
13 years agoHonored Guest
Unity & Hydra
I've been spinning my wheels trying to figure out how to tweak scripts for my OR unity project so I can use the hydra's joystick to control movement (w,a,s,d)- is there anyone who could point me in the right direction? It seems to be a simple problem but I'm very new to scripting and this has me stumped!
Would there a hydra equivalent for its joystick to getkeydown or getaxis? If this isn't an appropriate place to ask this just let me know.
Would there a hydra equivalent for its joystick to getkeydown or getaxis? If this isn't an appropriate place to ask this just let me know.
11 Replies
Replies have been turned off for this discussion
- drashHeroic ExplorerHi Caine!
Assuming you're starting with the Sixense plugin from the Unity asset store, and have dropped a "Sixense Input" component somewhere in your scene that is always active, you can do something like this:float forwardInput = 0f;
float turnInput = 0f;
SixenseInput.Controller hydraController = SixenseInput.GetController (SixenseHands.RIGHT);
if(hydraController != null && hydraController.Enabled && !hydraController.Docked)
{
forwardInput = hydraController.JoystickY;
turnInput = hydraController.JoystickX;
} - CaineHonored Guest
"drash" wrote:
Hi Caine!
Assuming you're starting with the Sixense plugin from the Unity asset store, and have dropped a "Sixense Input" component somewhere in your scene that is always active, you can do something like this:float forwardInput = 0f;
float turnInput = 0f;
SixenseInput.Controller hydraController = SixenseInput.GetController (SixenseHands.RIGHT);
if(hydraController != null && hydraController.Enabled && !hydraController.Docked)
{
forwardInput = hydraController.JoystickY;
turnInput = hydraController.JoystickX;
}
Thanks so much drash - I'm going to play with this when I'm home from work, scripting as a newb is super daunting but it is great there is such a helpful community out here :)
I am using the setup you described - So if I can get the above working I'm thinking incorporating the returned values for forwardInput and turnInput into my script that works with the mecanim control of the player avatar should be fairly straightforward.
Thanks again, if I can ever do you a solid to return the favour just let me know. - space123321ExplorerPlease keep us posted on your progress - I am a total beginner with coding and have zero experience. I have a similar post going a few down from here where I have the hands working in my scene however do not have any WASD movement and can't seem to get it to work. The advice that I received on the forum ands up with compiling issues and I do not know enough about the code to figure it out lol...
This is my post - the advise given might be of help to you?
https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=1322 - CaineHonored Guest
"space123321" wrote:
Please keep us posted on your progress - I am a total beginner with coding and have zero experience. I have a similar post going a few down from here where I have the hands working in my scene however do not have any WASD movement and can't seem to get it to work. The advice that I received on the forum ands up with compiling issues and I do not know enough about the code to figure it out lol...
This is my post - the advise given might be of help to you?
https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=1322
Hi Space - happy to keep you posted - I am coming to all of this as a newb and would be happy to help a fellow newb any way I can. Maybe take a look at my project and let me know if you are going for a similar setup and I can take you through the steps I did. - CaineHonored Guestdrash - thanks so much, I got it working quickly thanks to your help.
Space - I'm not sure if this will help you with your setup but here's how I got mine working -
-Have all the pre-requisites drash mentions;
-Added the following under my C# script that feeds values to the mecanim system animating my player avatar under fixed update:
SixenseInput.Controller hydraController = SixenseInput.GetController (SixenseHands.RIGHT);
float h = hydraController.JoystickX;
float v = hydraController.JoystickY;
I'm planning on re-adding functionality for w,a,s,d as doing this the way I have I ended up needing to 'comment out' where h & v were set to input.getaxis("Horizontal"), etc. I'm assuming I can do this by just repeating all the relevant mecanim tie-in's and just set a different value for the keyboard horizontal and vertical axes. Also going to take another stab at implementing the 'if' part drash suggested so that when the hydra is docked the joystick won't move the player - I am most likely butchering the correct terminology here. - space123321ExplorerAwesome that you got it working! In terms of my situation, I have simply applied the hydra hands to the OVRPlayerController by attaching them to the Right Camera (thanks to Cybereailty's advice). I have full hand movement via the hydra's and player movement via the keyboard - I simply can't figure out where to add the script mentioned above to get WASD movement via the Hydra for the OVRPlayerController prefab.
By the way - did I mention how much I love being a totally beginner and not having a clue what I am doing lol... so many ideas, not enough brains lol!!! - CaineHonored GuestOk, so, blind leading the blind but looking at the OVRPlayerController script and doing my best to apply what I learned from drash I'm thinking something like the following:
Tie in hydra joystick input from the right hydra by adding:
SixenseInput.Controller hydraController = SixenseInput.GetController (SixenseHands.RIGHT);
Add variables like:
float joyY = 0f;
float joyX = 0f;
joyX = hydraController.JoystickX;
joyY = hydraController.JoystickY;
so you can get some values returned from the joystick input that you can use - then in the section dealing with keyboard input (doesn't have to be there, but seems logical if I was searching through it) - add some 'if' statements so where your joyY variable has a value greater than 0 moveForward = true, less than 0 moveBack = true, and same for the joyX variable but for moveLeft and Right. It might be a good idea to also have the move variables set back to false when the joystick isn't meant to trigger them... - CosbyTronHonored Guest
"Caine" wrote:
- add some 'if' statements so where your joyY variable has a value greater than 0 moveForward = true, less than 0 moveBack = true, and same for the joyX variable but for moveLeft and Right. It might be a good idea to also have the move variables set back to false when the joystick isn't meant to trigger them...
That will definitely work, but if its reduced to "If > 0 Move Forward, else Don't" you'll lose the benefit of analog control. I haven't used the OVRPlayerController, so this is just a guess skimming the script, but you might be able to apply your JoystickX/Y value to MoveScale to have the movement speed scale with the analog stick (again, a guess :-) ).
You are right about your if statement, you can change the existing:
if (Input.GetKey(KeyCode.W)) moveForward = true;
to
if (controller.JoystickY >= 0.1f) moveForward = true;
I know this is a forum cliche, but you may have an easier time building your own script from scratch than trying to use the OVRPlayerController. I only suggest that because a lot of the code in PlayerController looks like its there to smooth out motion using WASD. Much of it isn't necessary for analog control, so you may be able to spare yourself some headaches.
If you are interested in experimenting with another approach, you could try using Unity's built in CharacterController, add the OVRCameraCameraController prefab to it, and move around with CharacterController.Move() or CharacterController.SimpleMove(). Just a thought :-D - CaineHonored GuestThanks for weighing in Cosbytron - very good points. I suspect my suggestion is really only a 'band-aid' approach. I'm assuming Space will need to stick with existing scripts for the time being, but I am slowly building confidence so I can do something more custom from scratch.
By the way, am looking forward to getting a chance to trying your demo, and everytime I see a post from you I think of the cartoon 'House of Cosbys' - have you seen that? :) - CosbyTronHonored GuestI have seen it, Theeeeoooo! :-D
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
- 3 years ago