TheKingElessar

Movement.lua

Jul 7th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. facing = 0 -- 1 = North, 2 = East, 3 = South, 4 = West
  2.  
  3. moveChance = 0
  4. turnChance = 0
  5. turning = false
  6.  
  7. function ChangeDirection(isRandom)
  8. if(isRandom) then
  9. turnTo = math.random(1, 4)
  10. end
  11.  
  12. turning = true
  13. end
  14.  
  15. function DetermineMovement()
  16.  
  17. if(turning) then
  18. if(not (facing == turnTo)) then
  19. turtle.turnRight()
  20. facing = facing + 1
  21.  
  22. if(facing == 5) then
  23. facing = 1
  24. end
  25. else
  26. turning = false
  27. end
  28. end
  29.  
  30. if(turtle.detect()) then
  31. turnChance = 101
  32. end
  33.  
  34. if(moveChance >= 5) then
  35. if(turnChance >= 10) then
  36. ChangeDirection(true)
  37. turnChance = 0
  38. else
  39. turnChance = turnChance + 1
  40. turtle.forward()
  41. end
  42.  
  43. moveChance = 0
  44. else
  45. moveChance = moveChance + 1
  46. end
  47. end
Add Comment
Please, Sign In to add comment