Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moveTo(targetX, targetZ, targetY)
- local currentX, currentZ, currentY = gps.locate()
- -- Calculate the differences between current and target coordinates
- local deltaX = targetX - currentX
- local deltaY = targetY - currentY
- local deltaZ = targetZ - currentZ
- print(targetZ)
- print(currentZ)
- print(deltaZ)
- -- Move along the Z-axis
- if deltaZ > 0 then
- print("Up")
- for i = 1, math.abs(deltaZ) do
- turtle.up()
- end
- elseif deltaZ < 0 then
- print("Down")
- for i = 1, math.abs(deltaZ) do
- turtle.down()
- end
- end
- -- Move along the X-axis
- if deltaX > 0 then
- for i = 1, deltaX do
- turtle.forward()
- end
- elseif deltaX < 0 then
- for i = 1, math.abs(deltaX) do
- turtle.back()
- end
- end
- -- Move along the Y-axis
- if deltaY > 0 then
- turtle.turnRight()
- for i = 1, deltaY do
- turtle.forward()
- end
- turtle.turnLeft()
- elseif deltaY < 0 then
- turtle.turnLeft()
- for i = 1, math.abs(deltaY) do
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- moveTo(616, 170, -586)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement