PickUpBox.cs 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion;
  4. using RootMotion.FinalIK;
  5. namespace RootMotion.Demos {
  6. /// <summary>
  7. /// Picking up a box shaped object with both hands.
  8. /// </summary>
  9. public class PickUpBox : PickUp2Handed {
  10. // Rotate the pivot of the hand targets by 90 degrees so we could grab the object from any direction
  11. protected override void RotatePivot() {
  12. // Get the flat direction towards the character
  13. Vector3 characterDirection = (pivot.position - interactionSystem.transform.position).normalized;
  14. characterDirection.y = 0f;
  15. // Convert the direction to local space of the object
  16. Vector3 characterDirectionLocal = obj.transform.InverseTransformDirection(characterDirection);
  17. // QuaTools.GetAxis returns a 90 degree ortographic axis for any direction
  18. Vector3 axis = QuaTools.GetAxis(characterDirectionLocal);
  19. Vector3 upAxis = QuaTools.GetAxis(obj.transform.InverseTransformDirection(interactionSystem.transform.up));
  20. // Rotate towards axis and upAxis
  21. pivot.localRotation = Quaternion.LookRotation(axis, upAxis);
  22. }
  23. }
  24. }