I have been trying to set up a scene where a cube moves when the left joystick is moved, and rotates when the right is moved. Basically I am trying to make a basic twin stick shooter.
Using some code provided here: http://answers.unity3d.com/questions/28790/twin-stick-shooter.html
I set up my inputs up accordingly and made them x or y-axis only and the types to joystick. But for some reason it still does not work. I am not getting any errors from the editor.
I think the reason my cube isn't moving is because my rh and rl (etc) values are fixed at zero. How come they don't change from between 1 to -1 (when I move my joysticks) like they are supposed to.
All help is appreciated. Thanks
asked Nov 27 '11 at 06:18 PM
Possible I'm wrong here, but unless I'm mistaken you can't read on-screen thumbsticks through unity's usual Input.GetAxis() methods. The original question was using a physical game controller, specifically a 360 one; these are supported by the Input class, but at present virtual on-screen controls for touch-screen devices are not.
Assuming you're using the on-screen sticks from the standard mobile assets, you have to read their value by accessing the script for them and reading the horizontal and vertical values there. In the standard mobile assets there's also a script FirstPersonControl that uses the DualJoysticks prefab.
You'll want variables to reference the joystick objects, like so...
These can be assigned in the inspector by dragging the left and right stick objects to them. Then you access the stick's positions through the leftStick.position and rightStick.position, which are simply vectors. Specifically, "leftStick.position.x" would be the equivalent of "Input.GetAxis("LeftStickHorizontal")".
The example script is fairly well-commented, and should help you with any other problems you run into (assuming you don't find it good enough for your needs as-is!)
Hope this helps!
answered Nov 27 '11 at 07:00 PM