Advertisement
LastTalon

Untitled

Nov 30th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. /**
  2.     * Calculates the difference between two angles.
  3.     *
  4.     * @param   a   The first operand. (a-b)
  5.     * @param   b   The second operand. (a-b)
  6.     * @return      The difference.
  7.     */
  8. private float DeltaAngle(float a, float b) {
  9.     float diff = a - b;
  10.     diff = diff % (Mathf.PI * 2);
  11.     if (diff > Mathf.PI)
  12.         diff = -Mathf.PI * 2 + diff;
  13.     return diff;
  14. }
  15.  
  16. float rot = DeltaAngle(desiredRotation, -(Mathf.Deg2Rad * GetComponent<Transform>().eulerAngles.y) - Mathf.PI / 2);
  17. if (Mathf.Abs(rot) >= rotationSpeed * Time.deltaTime)
  18.     rot = Mathf.Sign(rot) * rotationSpeed;
  19. else
  20.     rot = rot / Time.deltaTime;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement