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.

54 line
1.6KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Jumps given number of times in the given direction for the given amount of seconds.
  8. /// </summary>
  9. class ActionJumpBy : ActionSequence
  10. {
  11. protected Vector3 point;
  12. float height;
  13. int jumps;
  14. public ActionJumpBy(Vector3 targetPoint, float targetHeight, int targetJumps, float targetDuration)
  15. : base(new ActionInstant[targetJumps])
  16. {
  17. point = targetPoint;
  18. jumps = targetJumps;
  19. height = targetHeight;
  20. duration = targetDuration;
  21. }
  22. public ActionJumpBy(Vector2 targetPoint, float targetHeight, int targetJumps, float targetDuration)
  23. : this((Vector3)targetPoint, targetHeight, targetJumps, targetDuration)
  24. {
  25. }
  26. public override ActionInstant Clone()
  27. {
  28. return new ActionJumpBy(point, height, jumps, duration);
  29. }
  30. public override ActionInstant Reverse()
  31. {
  32. return new ActionJumpBy(-point, height, jumps, duration);
  33. }
  34. public override void Start()
  35. {
  36. float coeff = 1F / jumps;
  37. Vector3 end = point * coeff;
  38. Vector3 cp1 = Vector3.up * height;
  39. Vector3 cp2 = end + cp1;
  40. ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
  41. for (int i = 0; i < jumps; i++)
  42. {
  43. actions[i] = singleJump;
  44. }
  45. base.Start();
  46. }
  47. }
  48. }