Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

75 linhas
2.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Moves the target with a cubic Bezier in relative coordinates.
  8. /// </summary>
  9. class ActionBezierRel : ActionInterval
  10. {
  11. protected Vector3 ep;
  12. protected Vector3 cp1;
  13. protected Vector3 cp2;
  14. protected Vector3 startPoint;
  15. protected Vector3 endPoint;
  16. protected Vector3 startControlPoint;
  17. protected Vector3 endControlPoint;
  18. public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
  19. : base(tgtDuration)
  20. {
  21. ep = tgtEnd;
  22. cp1 = tgtSCP;
  23. cp2 = tgtECP;
  24. }
  25. public ActionBezierRel(Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
  26. : this((Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
  27. {
  28. is2d = true;
  29. }
  30. /// <summary>
  31. /// Returns a copy of the action.
  32. /// </summary>
  33. public override ActionInstant clone()
  34. {
  35. return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
  36. }
  37. /// <summary>
  38. /// Returns the reversed version of the action, if it is possible.
  39. /// </summary>
  40. public override ActionInstant reverse()
  41. {
  42. return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration);
  43. }
  44. /// <summary>
  45. /// This method is called at the action start.
  46. /// </summary>
  47. public override void start()
  48. {
  49. base.start();
  50. startPoint = target.transform.position;
  51. endPoint = startPoint + ep;
  52. startControlPoint = startPoint + cp1;
  53. endControlPoint = startControlPoint + cp2;
  54. }
  55. /// <summary>
  56. /// This method is called every frame update.
  57. /// </summary>
  58. public override void stepInterval(float dt)
  59. {
  60. float t = timer / duration;
  61. Vector3 newPosition = (((-startPoint
  62. + 3 * (startControlPoint - endControlPoint) + endPoint) * t
  63. + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
  64. 3 * (startControlPoint - startPoint)) * t + startPoint;
  65. transform.position = newPosition;
  66. }
  67. }
  68. }