onsdag 10 juni 2015

Arduino to Unity Project Part 8: Adding a second analog stick



Once I knew how to get input from one controller, send it to Unity and use it in a script there, it was very easy to replicate. I just connected the second stick to the arduino just like I connected the first one. The sent data from both sticks over serial. In Unity I only had to make it so that position data from the right stick was not used to do tranform.Translate() in unity but instead transform.Rotate():
http://docs.unity3d.com/ScriptReference/Transform.Rotate.html

For moving the FPSCamera-objekt right or left, I sent a vector of (0, Righstick X-position, 0) to  rotate around the Y-axis. To get this right, I also had to state to the function to rotate in relation to the world(the scene) y-axis and not the object itself.

Then I repeated this function call but for rotation around the X-axis in order to move the FPSCamera-objekt up/down.


This was the result (sorry for bad filming, It starts to get really hard to film and control the two thumbsticks at the same time!)

Arduino to Unity: double thumbsticks-input from Evert Lagerberg on Vimeo.

Inga kommentarer:

Skicka en kommentar