Advertisement
einsteinmaster96

movement.lua

Jan 4th, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | Gaming | 0 0
  1. current_x = 0
  2. current_y = 0
  3.  
  4. function move_back_to ( y )
  5.     turtle.turnLeft()
  6.     turtle.turnLeft()
  7.     while current_y > y do
  8.         turtle.dig()
  9.         res = turtle.forward()
  10.         if res then
  11.             current_y = current_y - 1
  12.         end
  13.     end
  14.     turtle.turnLeft()
  15.     turtle.turnLeft()
  16. end
  17.  
  18. function move_forward_to ( y )
  19.     while current_y < y do
  20.         turtle.dig()
  21.         res = turtle.forward()
  22.         if res then
  23.             current_y = current_y + 1
  24.         end
  25.     end
  26. end
  27.  
  28. function move_left_to ( x )
  29.     turtle.turnLeft()
  30.     while current_x > x do
  31.         turtle.dig()
  32.         res = turtle.forward()
  33.         if res then
  34.             current_x = current_x - 1
  35.         end
  36.     end
  37.     turtle.turnRight()
  38. end
  39.  
  40. function move_right_to ( x )
  41.     turtle.turnRight()
  42.     while current_x < x do
  43.         turtle.dig()
  44.         res = turtle.forward()
  45.         if res then
  46.             current_x = current_x + 1
  47.         end
  48.     end
  49.     turtle.turnLeft()
  50. end
  51.  
  52. function move_to ( x , y )
  53.     if x > current_x then
  54.         move_right_to(x)
  55.     end
  56.     if x < current_x then
  57.         move_left_to(x)
  58.     end
  59.     if y > current_y then
  60.         move_forward_to(y)
  61.     end
  62.     if y < current_y then
  63.         move_back_to(y)
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement