Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
To repozytorium jest zarchiwizowane. Możesz wyświetlać pliki i je sklonować, ale nie możesz do niego przepychać zmian lub otwierać zgłoszeń/Pull Requestów.

50 wiersze
1.3KB

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