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.

40 lines
1.2KB

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