- Home /
Unity touchpad not working to rotate an object
Hi guys, I'm currently developing a game for android and before moving onto the artwork, I decided to work on the control systems and make sure they work correctly. However I seem to be having trouble getting the touchpad to work.
I wrote two different types of code, one worked using the keyboard, the other didn't work at all.
The keyboard working code is:
var speed : float = 1;
function Update () {
var movementz = Input.GetAxis ("Vertical") speed; var movementx = Input.GetAxis ("Horizontal") speed;
transform.Rotate(movementx, 0, movementz);
}
The none working code is :
var movement : Vector3 = Vector3.zero; var speed : float = 1;
function Update () {
movement.z = Input.GetAxis ("Vertical"); movement.x = Input.GetAxis ("Horizontal");
transform.Rotate(movement * speed);
}
the touchpad is set up for a 50x50 pixel size at position 0,0,0 so it is in the bottom corner of the screen with a dead zone (normailised) at 0.5, 0.5.
I checked the input axes and one set is set for keyboard and another set is for joystick (Which I'm assuming is standard)
Answer by masha · Nov 12, 2012 at 12:25 PM
The joystick referenced in the Input axes refers to an actual joystick, not an on screen representation (which is what I am assuming you are using).
In order to use a touch screen joystick, add this script to a GUI texture:
Then, replace your code with :
var speed : float = 1;
var movement : Vector3 = Vector3.zero;
var joystick : Joystick;
function Update ()
{
var movementz = joystick.position.y * speed;
var movementx = joystick.position.x * speed;
transform.Rotate(movementx, 0, movementz);
}
To get the joystick script in js, and get more information about how to use it, I suggest you try out the Penelope tutorial on the Unity website.
Your answer
Follow this Question
Related Questions
Converting Android Axis to Unity Axis 0 Answers
Smooth Follow Camera Rotate on Z-Axis? 2 Answers
A node in a childnode? 1 Answer
Alternate command for rotation on Android ? 1 Answer
Rotation on Android vs. PC 0 Answers