Guest User

Untitled

a guest
Aug 1st, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. local tarX, tarY, tarZ = unpack(tArgs)
  4.  
  5. tarX = tonumber(tarX)
  6. tarY = tonumber(tarY)
  7. tarZ = tonumber(tarZ)
  8.  
  9. local function round(a) --round to integer
  10. return math.floor(a+0.5)
  11. end
  12.  
  13. local function F(a, x) --this is the parabola function
  14. return math.floor(0.5+((3*x*(a+58)*(a-x))/(a^2)))
  15. end
  16.  
  17. local function refill() --refill the launcher
  18. turtle.suckUp()
  19. turtle.forward()
  20. turtle.dropDown()
  21. turtle.back()
  22. end
  23.  
  24. local launcher = peripheral.wrap("bottom")
  25.  
  26. --home coordinates
  27. local homeX = 969
  28. local homeY = 4
  29. local homeZ = 654
  30.  
  31. --get the distance to target using pythagoras' theorem
  32. local dist = math.sqrt((tarX-homeX)^2+(tarZ-homeZ)^2)
  33.  
  34. local a = dist
  35.  
  36. if tarY > homeY then --aim further away
  37. while (tarY-homeY) > F(a, dist) do
  38. a = a+1
  39. end
  40. elseif tarY < homeY then --aim closer
  41. while (tarY - homeY) < F(a, dist) do
  42. a = a-1
  43. end
  44. else --don't need to adjust
  45. a = dist
  46. end
  47.  
  48.  
  49. print("dist = "..dist)
  50. print("a = "..a)
  51.  
  52. -- fancy math :D
  53. tarX = homeX+(a/dist)*(tarX-homeX)
  54. tarZ = homeZ+(a/dist)*(tarZ-homeZ)
  55.  
  56. print("Aiming at "..round(tarX).."/0/"..round(tarZ))
  57. launcher.setTarget(round(tarX), 0, round(tarZ))
  58. launcher.launch()
  59. sleep(1)
  60. refill()
Advertisement
Add Comment
Please, Sign In to add comment