SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //I take input from the horizontal and vertical axis which are the left joy pad on most XBOX controllers and the WASD
  2. //by standard default in all unity project. You should not need the cross platform manager for this.
  3.  
  4. //The math function takes the Atan2 of the two inputs and then converts them from a rad to degree. This should return
  5. // your joystick position as a value of 0-359.999
  6. float joyStickAngle = Mathf.Atan2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical")) * Mathf.Rad2Deg;
  7. //You then apply this value to the eulerAngles of the object to rotate it around it's host to match where the
  8. // joy stick is working. this works currently with no magic numbers because my sprite pivot is north I beleive
  9. //if you find the sprite or object rotating opposie of the joystick you may need to put -joyStickAngle to invert it.
  10. objectToRotate.transform.eulerAngles = new Vector3 (0, 0, joyStickAngle);
  11.  
  12. //If you are using tank controls you can add listners in the input settings for the second joystick and listen to them instead
  13. //in the math problem
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top