You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

51 lines
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. class ActionBezierRel : ActionInterval
  5. {
  6. protected Vector3 ep;
  7. protected Vector3 cp1;
  8. protected Vector3 cp2;
  9. protected Vector3 startPoint;
  10. protected Vector3 endPoint;
  11. protected Vector3 startControlPoint;
  12. protected Vector3 endControlPoint;
  13. public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
  14. : base(tgtDuration)
  15. {
  16. ep = tgtEnd;
  17. cp1 = tgtSCP;
  18. cp2 = tgtECP;
  19. }
  20. public override Action clone()
  21. {
  22. return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
  23. }
  24. public override Action reverse()
  25. {
  26. return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration);
  27. }
  28. public override void start()
  29. {
  30. base.start();
  31. startPoint = target.transform.position;
  32. endPoint = startPoint + ep;
  33. startControlPoint = startPoint + cp1;
  34. endControlPoint = startControlPoint + cp2;
  35. }
  36. public override void stepInterval(float dt)
  37. {
  38. float t = timer / duration;
  39. Vector3 newPosition = (((-startPoint
  40. + 3 * (startControlPoint - endControlPoint) + endPoint) * t
  41. + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
  42. 3 * (startControlPoint - startPoint)) * t + startPoint;
  43. transform.position = newPosition;
  44. }
  45. }