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.

53 lines
1.6KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Jumps to the given point for the given amount of seconds in the given amounts of jumps.
  8. /// </summary>
  9. class ActionJumpTo : ActionSequence
  10. {
  11. protected Vector3 point;
  12. float height;
  13. int jumps;
  14. public ActionJumpTo(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 ActionJumpTo(Vector2 targetPoint, float targetHeight, int targetJumps, float targetDuration)
  23. : this((Vector3)targetPoint, targetHeight, targetJumps, targetDuration)
  24. {
  25. locks = Axises.z;
  26. }
  27. public override ActionInstant Clone()
  28. {
  29. return new ActionJumpTo(point, height, jumps, duration);
  30. }
  31. public override void Start()
  32. {
  33. float coeff = 1F / jumps;
  34. if (locks != Axises.none)
  35. LockAxises(ref point);
  36. Vector3 start = target.gameObject.transform.position;
  37. Vector3 end = (point - start) * 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. }