- Home /
Joystick trouble...
So I'm working with virtual joysticks, and after some work I managed to finally make a successful joystick that controls both movement and rotation, however it's not as smooth as I'd like, my code to make it rotate is
if (moveStick.position.x > 0 || moveStick.position.y > 0)
{
targetRotation = Quaternion.LookRotation (movement);
///Both Methods for roatation work below though I feel as thought the commented out one works a lot better
//character.transform.eulerAngles = new Vector3 (character.transform.eulerAngles.x, Mathf.Atan2 (moveStick.position.x, moveStick.position.y) * Mathf.Rad2Deg, character.transform.eulerAngles.z);
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
}
now I've done some research and most say to create an empty game object and make the player a child of it and set its rotation to look at it, however, after many failed attempts I still have no idea how to do this nor comprehend the idea. I have another joystick declared and would like to how can I make the empty game object mirror the joystick in the center and just have the player look at that direction, if someone could explain this it would help ALOT. P.S much thanks to those who have helped me especially robertbu who's been a life saver.