Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local tarX, tarY, tarZ = unpack(tArgs)
- tarX = tonumber(tarX)
- tarY = tonumber(tarY)
- tarZ = tonumber(tarZ)
- local function round(a) --round to integer
- return math.floor(a+0.5)
- end
- local function F(a, x) --this is the parabola function
- return math.floor(0.5+((3*x*(a+58)*(a-x))/(a^2)))
- end
- local function refill() --refill the launcher
- turtle.suckUp()
- turtle.forward()
- turtle.dropDown()
- turtle.back()
- end
- local launcher = peripheral.wrap("bottom")
- --home coordinates
- local homeX = 969
- local homeY = 4
- local homeZ = 654
- --get the distance to target using pythagoras' theorem
- local dist = math.sqrt((tarX-homeX)^2+(tarZ-homeZ)^2)
- local a = dist
- if tarY > homeY then --aim further away
- while (tarY-homeY) > F(a, dist) do
- a = a+1
- end
- elseif tarY < homeY then --aim closer
- while (tarY - homeY) < F(a, dist) do
- a = a-1
- end
- else --don't need to adjust
- a = dist
- end
- print("dist = "..dist)
- print("a = "..a)
- -- fancy math :D
- tarX = homeX+(a/dist)*(tarX-homeX)
- tarZ = homeZ+(a/dist)*(tarZ-homeZ)
- print("Aiming at "..round(tarX).."/0/"..round(tarZ))
- launcher.setTarget(round(tarX), 0, round(tarZ))
- launcher.launch()
- sleep(1)
- refill()
Advertisement
Add Comment
Please, Sign In to add comment