- Home /
iOS Rotation Chararacter with joystick
Hello everyone! I have a huge problem here.. i have one last thing to do to finish the prototype and im stuck bad here.... I wanna the right joystick rotate the character depending the joystick's position.. and i cant figure out..i looked in unity answers but didn't found much.. the only close code i have is this one
var rotateJoystick : Joystick;
function Update()
{
if(rotateJoystick.position.x > 0 || rotateJoystick.position.y > 0) {
var rotationDirection = Vector3(rotateJoystick.position.x, 0 , rotateJoystick.position.y);
rotationDirection = rotationDirection.normalized;
var rotation = Quaternion.LookRotation(rotationDirection);
transform.rotation = rotation;
}
}
but still doesn't work right... any help? :)
What do you mean by 'iOS' and 'Joystick.' Are you talking about a $$anonymous$$oga controller? Are you using an iOS device as a controller? Or are you talking about the virtual joystick controller that comes with the standard mobile asset package.
Answer by Aldebaran2012 · Feb 25, 2013 at 07:22 PM
Hey, this work for me. I hope than for you too.
if (pp_joystickForLook.position.x != 0 || pp_joystickForLook.position.y != 0)
{
// Scale joystick input with rotation speed
var camRotation = pp_joystickForLook.position;
camRotation.x *= rotationSpeed.x;
camRotation.y *= -rotationSpeed.y;
camRotation *= Time.deltaTime;
// Rotate around the character horizontally in world, but use local space
// for vertical rotation
transform.Rotate(0, camRotation.x, 0, Space.World);
transform.Rotate(camRotation.y, 0, 0);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613091629im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to use the joystick to control the character 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
FPS Camera rotates on Z when using a joystick 0 Answers
How to make my player to look in the direction of right joystick's input direction 0 Answers
how can i let my player move converse? 0 Answers