Advertisement
Alexr360

Move to

Mar 13th, 2024 (edited)
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. function moveTo(targetX, targetZ, targetY)
  2.     local currentX, currentZ, currentY = gps.locate()
  3.    
  4.     -- Calculate the differences between current and target coordinates
  5.     local deltaX = targetX - currentX
  6.     local deltaY = targetY - currentY
  7.     local deltaZ = targetZ - currentZ
  8.    
  9.     print(targetZ)
  10.     print(currentZ)
  11.     print(deltaZ)
  12.  
  13.     -- Move along the Z-axis
  14.     if deltaZ > 0 then
  15.         print("Up")
  16.         for i = 1, math.abs(deltaZ) do
  17.             turtle.up()
  18.         end
  19.     elseif deltaZ < 0 then
  20.         print("Down")
  21.         for i = 1, math.abs(deltaZ) do
  22.             turtle.down()
  23.         end
  24.     end
  25.  
  26.     -- Move along the X-axis
  27.     if deltaX > 0 then
  28.         for i = 1, deltaX do
  29.             turtle.forward()
  30.         end
  31.     elseif deltaX < 0 then
  32.         for i = 1, math.abs(deltaX) do
  33.             turtle.back()
  34.         end
  35.     end
  36.    
  37.     -- Move along the Y-axis
  38.     if deltaY > 0 then
  39.         turtle.turnRight()
  40.         for i = 1, deltaY do
  41.             turtle.forward()
  42.         end
  43.         turtle.turnLeft()
  44.     elseif deltaY < 0 then
  45.         turtle.turnLeft()
  46.         for i = 1, math.abs(deltaY) do
  47.             turtle.forward()
  48.         end
  49.         turtle.turnRight()
  50.     end
  51. end
  52.  
  53.  
  54. moveTo(616, 170, -586)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement