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.

47 lines
1.1KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. class ActionRotateTo : ActionInterval
  5. {
  6. protected Vector3 value;
  7. protected Vector3 path;
  8. public ActionRotateTo(Vector3 tgtValue, float tgtDuration)
  9. : base(tgtDuration)
  10. {
  11. value = tgtValue;
  12. }
  13. public ActionRotateTo(float angle, float tgtDuration)
  14. : this(new Vector3(0, 0, angle), tgtDuration)
  15. {
  16. is2d = true;
  17. }
  18. public override Action clone()
  19. {
  20. return new ActionRotateTo(value, duration);
  21. }
  22. public override void start()
  23. {
  24. base.start();
  25. path = new Vector3();
  26. for (int i = 0; i < 3; i++)
  27. {
  28. float t = value[i];
  29. float f = transform.rotation.eulerAngles[i];
  30. if (Math.Abs(t - f) < Math.Abs(t + 360 - f))
  31. path[i] = t - f;
  32. else
  33. path[i] = t + 360 - f;
  34. }
  35. }
  36. public override void stepInterval(float dt)
  37. {
  38. float d = dt / duration;
  39. Vector3 tgt = path * d;
  40. transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
  41. }
  42. }