animator.script 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. go.property("start_position", vmath.vector3())
  2. go.property("end_position", vmath.vector3())
  3. go.property("start_rotation", vmath.vector3())
  4. go.property("end_rotation", vmath.vector3())
  5. go.property("start_scale", vmath.vector3(1, 1, 1))
  6. go.property("end_scale", vmath.vector3(1, 1, 1))
  7. go.property("duration", 2)
  8. local function should_animate_position(self)
  9. return self.start_position ~= self.end_position
  10. end
  11. local function should_animate_rotation(self)
  12. return self.start_rotation ~= self.end_rotation
  13. end
  14. local function should_animate_scale(self)
  15. return self.start_scale ~= self.end_scale
  16. end
  17. local function reset_position_rotation_scale(self)
  18. if should_animate_position(self) then
  19. go.set_position(self.start_position)
  20. end
  21. if should_animate_rotation(self) then
  22. go.set(".", "euler", self.start_rotation)
  23. end
  24. if should_animate_scale(self) then
  25. go.set_scale(self.start_scale)
  26. end
  27. end
  28. local function animate(self)
  29. reset_position_rotation_scale(self)
  30. if should_animate_position(self) then
  31. go.animate(".", "position", go.PLAYBACK_LOOP_PINGPONG, self.end_position, self.easing, self.duration)
  32. end
  33. if should_animate_rotation(self) then
  34. go.animate(".", "euler", go.PLAYBACK_LOOP_PINGPONG, self.end_rotation, self.easing, self.duration)
  35. end
  36. if should_animate_scale(self) then
  37. go.animate(".", "scale", go.PLAYBACK_LOOP_PINGPONG, self.end_scale, self.easing, self.duration)
  38. end
  39. end
  40. function on_message(self, message_id, message, sender)
  41. if message_id == hash("restart") then
  42. self.easing = message.easing
  43. animate(self)
  44. end
  45. end