spinner.script 785 B

12345678910111213141516171819202122
  1. function init(self)
  2. self.t = 0 -- <1>
  3. self.speed = 16 -- <2>
  4. end
  5. function update(self, dt)
  6. self.t = self.t + dt -- <3>
  7. local step = math.floor(self.t * self.speed) -- <4>
  8. local angle = math.pi / 6 * step -- <5>
  9. local rot = vmath.quat_rotation_z(-angle) -- <6>
  10. go.set_rotation(rot) -- <7>
  11. end
  12. --[[
  13. 1. Store a timer value (seconds elapsed) in the current script component (accessed through `self`).
  14. 2. A speed value. How many rotation steps to perform each second.
  15. 3. Increase timer value with the delta time elapsed since last `update()`.
  16. 4. Calculate which step to rotate to.
  17. 5. Calculate rotation angle (in radians) based on which step to rotate to.
  18. 6. Create a rotation quaternion with `angle` rotation around the Z axis.
  19. 7. Set the rotation on the current game object.
  20. --]]