Advertisement
Guest User

GTA V Look Rotation method like Unity's (from sollaholla)

a guest
Nov 15th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /// <summary>
  2. /// Get's the rotation needed to face the specified direction.
  3. /// </summary>
  4. /// <param name="direction">The direction to face.</param>
  5. /// <param name="planeNormal">Projects the rotation on this normal vector.</param>
  6. /// <returns></returns>
  7. public static Quaternion LookRotation(Vector3 direction, Vector3 planeNormal)
  8. {
  9. // Calculate the up rotation.
  10. var upRotation = Quaternion.FromToRotation(Vector3.WorldUp, planeNormal);
  11.  
  12. // Get the signed angle from (0, 1, 0) to the direction delta.
  13. var sin = Vector3.SignedAngle(Vector3.RelativeFront, direction, planeNormal);
  14.  
  15. // Calculate the facing rotation.
  16. var forwardRotation = Quaternion.Euler(0, 0, sin);
  17.  
  18. // Get the look rotation by multiplying both upQ and facingQ.
  19. var lookRotation = upRotation * forwardRotation;
  20.  
  21. // Return the new rotation.
  22. return lookRotation;
  23. }
  24.  
  25. /// <summary>
  26. /// Get's the rotation needed to face the specified direction.
  27. /// Default plane normal is our up vector.
  28. /// </summary>
  29. /// <param name="direction">The direction to face.</param>
  30. /// <returns></returns>
  31. public static Quaternion LookRotation(Vector3 direction)
  32. {
  33. return LookRotation(direction, Vector3.WorldUp);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement