galygious

goto

Jul 1st, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. local galymove = require("galymoveAPI")
  2.  
  3. local function moveTowards(targetX, targetY, targetZ)
  4. local currentPosition = galymove.getPosition()
  5. local deltaX = targetX - currentPosition.x
  6. local deltaY = targetY - currentPosition.y
  7. local deltaZ = targetZ - currentPosition.z
  8.  
  9. -- Move in the X-axis
  10. if deltaX > 0 then
  11. galymove.move("f", deltaX)
  12. elseif deltaX < 0 then
  13. galymove.move("b", math.abs(deltaX))
  14. end
  15.  
  16. -- Move in the Y-axis
  17. if deltaY > 0 then
  18. galymove.move("u", deltaY)
  19. elseif deltaY < 0 then
  20. galymove.move("d", math.abs(deltaY))
  21. end
  22.  
  23. -- Move in the Z-axis
  24. if deltaZ > 0 then
  25. galymove.move("r", deltaZ)
  26. elseif deltaZ < 0 then
  27. galymove.move("l", math.abs(deltaZ))
  28. end
  29. end
  30.  
  31. -- Specify the target coordinates
  32. local targetX = 10
  33. local targetY = 5
  34. local targetZ = 3
  35.  
  36. -- Move the turtle towards the target coordinates
  37. moveTowards(targetX, targetY, targetZ)
  38.  
  39. -- Retrieve and print the current position
  40. local currentPosition = galymove.getPosition()
  41. print("Current Position: x = " .. currentPosition.x .. ", y = " .. currentPosition.y .. ", z = " .. currentPosition.z)
  42.  
Advertisement
Add Comment
Please, Sign In to add comment