PickUpSphere.cs 798 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion;
  4. using RootMotion.FinalIK;
  5. namespace RootMotion.Demos {
  6. /// <summary>
  7. /// Picking up a sphere with both hands.
  8. /// </summary>
  9. public class PickUpSphere : PickUp2Handed {
  10. // Rotate the pivot of the hand targets so we could grab the object from any direction
  11. protected override void RotatePivot() {
  12. // Find the center of the hand bones
  13. Vector3 handsCenter = Vector3.Lerp(interactionSystem.ik.solver.leftHandEffector.bone.position, interactionSystem.ik.solver.rightHandEffector.bone.position, 0.5f);
  14. // Direction from that center to the interaction object
  15. Vector3 dir = obj.transform.position - handsCenter;
  16. // Rotate the pivot of the hand targets
  17. pivot.rotation = Quaternion.LookRotation(dir);
  18. }
  19. }
  20. }