TransferMotion.cs 763 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.FinalIK;
  4. namespace RootMotion.Demos {
  5. /// <summary>
  6. /// Transfer motion from this Transform to the "to" Transform.
  7. /// </summary>
  8. public class TransferMotion : MonoBehaviour {
  9. [Tooltip("The Transform to transfer motion to.")]
  10. public Transform to;
  11. [Tooltip("The amount of motion to transfer.")]
  12. [Range(0f, 1f)] public float transferMotion = 0.9f;
  13. private Vector3 lastPosition;
  14. void OnEnable() {
  15. lastPosition = transform.position;
  16. }
  17. void Update() {
  18. Vector3 delta = transform.position - lastPosition;
  19. // Add the position delta of this Transform to the other Transform
  20. to.position += delta * transferMotion;
  21. lastPosition = transform.position;
  22. }
  23. }
  24. }