Blog Archive

Wednesday 26 November 2014

Razer Hydra: Interaction Part 1

Finally I got the Razer Hydra controller and started to work on the interaction of my game. First challenge was to implement the controller in the Unity engine. Fortunately the creators of this controller already dealt with this problem by releasing a special asset in Unity Store. Using it I was already able to have some primitive interaction. The problem was that the interaction provided by Razer was not ideally fitting my game so I had to rewrite the scripts.

I started to write a simple script for player movement. At the end I`ve got the possibility to walk and rotate my model using the sticks of the Razer Hydra. Beside it the player is able to crouch and jump. During this scripting process I`ve got all the specific knowledge I need to work with Razer Hydra so the next processes went quite unproblematic.

The next step was the hand tracking. I changed the scripts of Razer Hydra to make the control other the motion tracking easier for me. I changed the model of the hands and made a new animations for it. As the result my virtual model is controlled fully by Razer Hydra. My virtual hands repeat the movements of my real hands. I can walk in the virtual spaces but I can not interact with the object around me. That was my next step.

Interacting with the virtual objects is not easy. There are different ways to produce this interaction. The easiest one is to check the collision with the interactive objects and add on collision action to stick the object to the hand. The object could become the child of the hand model or it could just take the position and rotation of it. I took the second direction. Beside it I decided to check the collision by ray-casting a sphere from the hands.  This method is more precise than just checking the collision of the object colliders. First test showed that this method works quite well. I am able to take the specific game object in my virtual hands and hold them as I do in the real life.

Next step was to make the possibility to throw this object. In my way to do it I had to add the riggidbody physique to the interactive game object with the gravity flag enabled. I also had to calculate the force of throwing. I do it by checking the direction in which the hand moved just before releasing the object. This check is a bit more complex than you could imagine because the check is done in all three dimensional axis. Beside it I calculate the speed of this motion to add a dynamic force to an object. It means that as hard you throw the object as faster is will move in the throw direction. Also the speed is affected by the object weight. So the throwing itself is a complex calculation of different things and already an interesting interaction with the game objects.

Now when the interaction with non static objects are done and I could use this interaction to move the object, to explore them or just to throw them away,  I can go to the next step: Interaction with the non static object. You can read about it in the next chapter of my "Intraction Guide".

As for now I leave here a video with some of the interactions that I described in this text.



No comments:

Post a Comment