Fly.lua 506 B

12345678910111213141516171819202122
  1. class "Fly"
  2. function Fly:Fly(flyBody)
  3. self.startPosition = Vector3(flyBody.position.x, flyBody.position.y, flyBody.position.z)
  4. self.body = flyBody
  5. self.direction = -1.0
  6. end
  7. function Fly:Update(elapsed)
  8. self.body:Translate(self.direction * elapsed * 150.0, 0.0, 0.0)
  9. if self.startPosition:distance(self.body.position) > 100 then
  10. if self.body.position.x < self.startPosition.x then
  11. self.direction = 1.0
  12. else
  13. self.direction = -1.0
  14. end
  15. end
  16. self.body.scale.x = self.direction * -1.0
  17. end