Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I take input from the horizontal and vertical axis which are the left joy pad on most XBOX controllers and the WASD
- //by standard default in all unity project. You should not need the cross platform manager for this.
- //The math function takes the Atan2 of the two inputs and then converts them from a rad to degree. This should return
- // your joystick position as a value of 0-359.999
- float joyStickAngle = Mathf.Atan2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical")) * Mathf.Rad2Deg;
- //You then apply this value to the eulerAngles of the object to rotate it around it's host to match where the
- // joy stick is working. this works currently with no magic numbers because my sprite pivot is north I beleive
- //if you find the sprite or object rotating opposie of the joystick you may need to put -joyStickAngle to invert it.
- objectToRotate.transform.eulerAngles = new Vector3 (0, 0, joyStickAngle);
- //If you are using tank controls you can add listners in the input settings for the second joystick and listen to them instead
- //in the math problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement