- Home /
Question by
iDeveloper2 · May 25, 2013 at 03:44 PM ·
movementcharactercontrollerjoystickleftmouseclick
Joystick movent and rotation on left joystick
Hi every one.
I have question how to rotate and move upward and backward character using left joystick. I search from unity question as well as other sources but nothing find any accurate answer. I am new to work on unity. Please help how to solved this problem. My code work on keyboad but not joystick.
var rotatePos = Input.GetAxis ("Horizontal") ? Input.GetAxis ("Horizontal") : joyStickInput(moveJoystick);
transform.Rotate(0, rotatePos * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var movePos = Input.GetAxis ("Vertical") ?
Input.GetAxis ("Vertical") : joyStickInput(moveJoystick);
var curSpeed = speed * movePos;
controller.SimpleMove(forward * curSpeed)
And this is joystick movement and rotation function
function joyStickInput (joystick : Joystick) {
var absJoyPos = Vector2 (Mathf.Abs(joystick.position.x),
Mathf.Abs(joystick.position.y));
var xDirection = (joystick.position.x > 0) ? 1 : -1;
var yDirection = (joystick.position.y > 0) ? 1 : -1;
return ( ( absJoyPos.x > absJoyPos.y) ? absJoyPos.x * xDirection : absJoyPos.y * yDirection);
}
Comment