Advertisement
ladyDia

GPS nav

Aug 19th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local a = {}
  2. local args = {...}
  3.  
  4. local counter = 4
  5. local numbering = 5
  6.  
  7. local posX = 0
  8. local posY = 0
  9. local posZ = 0
  10.  
  11. posX, posY, posZ = gps.locate(5)
  12.  
  13. local startX = posX
  14. local startY = posY
  15. local startZ = posZ
  16.  
  17. local direction = 0
  18.  
  19. local inventory = 1
  20.  
  21. function a.orient()
  22. turtle.forward()
  23. posX, posY, posZ = gps.locate(5)
  24. if posX-startX > 0 then
  25. direction = 0
  26. end
  27. if posZ-startZ > 0 then
  28. direction = 1
  29. end
  30. if posX-startX < 0 then
  31. direction = 2
  32. end
  33. if posX-startX < 0 then
  34. direction = 3
  35. end
  36. end
  37.  
  38. function a.moveTo(targetX,targetY,targetZ)
  39. posX, posY, posZ = gps.locate(5)
  40. while posY > targetY do
  41. turtle.down()
  42. end
  43. while posY < targetY do
  44. turtle.up()
  45. end
  46.  
  47. if posX > targetX then
  48. a.rotateTo(2)
  49. end
  50. if posX < targetX then
  51. a.rotateTo(0)
  52. end
  53. while posX ~= targetX do
  54. turtle.forward()
  55. end
  56.  
  57. if posZ > targetZ then
  58. a.rotateTo(3)
  59. end
  60. if posZ < targetZ then
  61. a.rotateTo(1)
  62. end
  63. while posZ ~= targetZ do
  64. turtle.forward()
  65. end
  66. end
  67.  
  68. function a.rotateTo(targetD)
  69. while direction ~= targetD
  70. if direction > 3 then
  71. direction = 0
  72. end
  73. if direction < 0 then
  74. direction = 3
  75. end
  76. if direction < targetD then
  77. direction = direction + 1
  78. turtle.turnRight()
  79. end
  80. if direction > targetD then
  81. direction = direction - 1
  82. turtle.turnLeft()
  83. end
  84. end
  85. end
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement