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.

50 line
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. class ActionJumpTo : ActionSequence
  7. {
  8. protected Vector3 point;
  9. float height;
  10. int jumps;
  11. public ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
  12. : base(new ActionInstant[tgtJumps])
  13. {
  14. point = tgtPoint;
  15. jumps = tgtJumps;
  16. height = tgtHeight;
  17. duration = tgtDuration;
  18. }
  19. public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
  20. : this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
  21. {
  22. is2d = true;
  23. }
  24. public override ActionInstant clone()
  25. {
  26. return new ActionJumpTo(point, height, jumps, duration);
  27. }
  28. public override void start()
  29. {
  30. float coeff = 1F / jumps;
  31. if (is2d)
  32. point.z = transform.position.z;
  33. Vector3 start = target.gameObject.transform.position;
  34. Vector3 end = (point - start) * coeff;
  35. Vector3 cp1 = Vector3.up * height;
  36. Vector3 cp2 = end + cp1;
  37. ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
  38. for (int i = 0; i < jumps; i++)
  39. {
  40. actions[i] = singleJump;
  41. }
  42. base.start();
  43. }
  44. }
  45. }