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.

43 lines
1.0KB

  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 override Action clone()
  14. {
  15. return new ActionRotateTo(value, duration);
  16. }
  17. public override void start()
  18. {
  19. base.start();
  20. path = new Vector3();
  21. for (int i = 0; i < 3; i++)
  22. {
  23. float t = value[i];
  24. float f = transform.rotation.eulerAngles[i];
  25. if (Math.Abs(t - f) < Math.Abs(t + 360 - f))
  26. path[i] = t - f;
  27. else
  28. path[i] = t + 360 - f;
  29. }
  30. }
  31. public override void stepInterval(float dt)
  32. {
  33. float d = dt / duration;
  34. Vector3 tgt = path * d;
  35. transform.Rotate(Vector3.up, tgt.y);
  36. transform.Rotate(Vector3.right, tgt.x);
  37. transform.Rotate(Vector3.forward, tgt.z);
  38. }
  39. }