uepyon

dist.lua

Mar 24th, 2024 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function getFaceTo()
  2.   local pos0 = vector.new(gps.locate())
  3.   turtle.forward()
  4.   local pos1 = vector.new(gps.locate())
  5.   local dist = pos1 - pos0
  6.   turtle.back()
  7.   local faceto = ""
  8.   if dist.x > 0 then
  9.     faceto = "west"
  10.   elseif dist.x < 0 then
  11.     faceto = "east"
  12.   elseif dist.z > 0 then
  13.     faceto = "north"
  14.   else
  15.     faceto = "south"
  16.   end
  17.   return faceto
  18. end
  19.  
  20. local function forback(dist)
  21.   d = dist
  22.   if d < 0 then
  23.     d = -d
  24.   end  
  25.   if dist > 0 then
  26.     print("forward:"..tostring(d))
  27.   else
  28.     print("back:"..tostring(d))
  29.   end
  30. end
  31.  
  32. local function dispStatus(pos, target, faceto)
  33.   print("pos:"..tostring(pos))
  34.   print("faceTo:"..faceto)
  35.   print("dist:"..tostring(target - pos))
  36. end
  37.  
  38. args = {...}
  39. x = tonumber(args[1])
  40. y = tonumber(args[2])
  41. z = tonumber(args[3])
  42. target = vector.new(x, y, z)
  43.  
  44. rednet.open("left")
  45. curpos = vector.new(gps.locate())
  46.  
  47. faceto = getFaceTo()
  48. dispStatus(curpos, target, faceto)
  49. dist = target - curpos
  50. forback(dist.z)
  51.  
Advertisement
Add Comment
Please, Sign In to add comment