etelan

Good Movement

Jan 2nd, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Require component
  2. local function proxyFor(name, required)
  3.   local address = component and component.list(name)()
  4.   if not address and required then
  5.     error("missing component '" .. name .. "'")
  6.   end
  7.   return address and component.proxy(address) or nil
  8. end
  9.  
  10.  
  11. --Require
  12. local drone = proxyFor("drone", true)
  13. local navigation = proxyFor("navigation", true)
  14. local m = proxyFor("modem", true)
  15.  
  16.  
  17.  
  18. -- Old Coords
  19. disX = -17
  20. disY = -100
  21. disZ = 0
  22.  
  23.  
  24. -- Open Port
  25. m.open(808)
  26.  
  27. --Initial Values
  28. local port = 808
  29. local startx, starty, startz = navigation.getPosition()
  30.  
  31. local function moveDirection(axis, worked, distance, start, port)
  32.    
  33.     -- IF WITHIN 1 BLOCK
  34.     while (worked > distance + 1 or worked < distance - 1) do
  35.      
  36.  
  37.       -- BROADCAST LOCATION
  38.       m.broadcast(port, axis .. ": " ..  worked)
  39.  
  40.       -- UPDATE LOCATION
  41.       x, y, z = navigation.getPosition()
  42.    
  43.       if axis == "x" then
  44.           worked = x - start
  45.       end
  46.        
  47.       if axis == "y" then
  48.           worked = y - start
  49.       end
  50.  
  51.       if axis == "z" then
  52.           worked = z - start
  53.       end
  54.  
  55.       -- FORWARD
  56.       if worked < distance then
  57.  
  58.         if axis == "x" then
  59.           drone.move(1,0,0)
  60.         end
  61.  
  62.         if axis == "y" then
  63.           drone.move(0,1,0)
  64.         end
  65.  
  66.         if axis == "z" then
  67.           drone.move(0,0,1)
  68.         end
  69.    
  70.       end
  71.        
  72.       -- REVERSE
  73.       if worked > distance then
  74.         if axis == "x" then
  75.           drone.move(-1,0,0)
  76.         end
  77.  
  78.         if axis == "y" then
  79.           drone.move(0,-1,0)
  80.         end
  81.  
  82.         if axis == "z" then
  83.           drone.move(0,0,-1)
  84.         end
  85.       end
  86.    
  87.     end
  88.  
  89. end
  90.  
  91. moveDirection("x", 0, 10, startx, 808)
Add Comment
Please, Sign In to add comment