gltf.script 857 B

12345678910111213141516171819202122232425
  1. -- This script controls the movement of track parts to create an infinite scrolling effect
  2. -- i.e. we don't move the car, we move the track.
  3. function init(self)
  4. local count = 6 -- Total number of track parts
  5. local part_size = 4 -- Size of each track part
  6. self.current_z = 0 -- Current z position of the track
  7. self.loop_at_z = part_size * (count - 2) -- Point at which to loop the track
  8. self.speed = 5 -- Movement speed of the track
  9. end
  10. function update(self, dt)
  11. -- Move the track forward based on speed and delta time
  12. self.current_z = self.current_z + self.speed * dt
  13. -- Loop the track position when it reaches the loop point
  14. if self.current_z > self.loop_at_z then
  15. self.current_z = self.current_z - self.loop_at_z
  16. end
  17. -- Update the position of the track game object
  18. go.set("/track", "position.z", self.current_z)
  19. end