Guest User

Untitled

a guest
Jun 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public int rotationOffset = 90;
  2.  
  3. void Update () {
  4. Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; // subtracting the position of the player from the mouse position.
  5. difference.Normalize(); //normalizing the vector meaning all the sum of the vector will be = to 1.
  6.  
  7. float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;//find the angle in degree.
  8. transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
  9.  
  10. }
Add Comment
Please, Sign In to add comment