Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a = peripheral.wrap("top")
- local modem = peripheral.wrap("right")
- local entity = peripheral.wrap("left")
- modem.open(70)
- local p = true
- local curX, curY, curZ = gps.locate()
- function fly()
- while true do
- a.launch(0,270,0.320)
- sleep(0.2)
- end
- end
- function trim(val, max)
- if val > max then
- return max
- end
- return val
- end
- parallel.waitForAll(
- fly,
- function()
- while true do
- if p then
- local x, y, z = gps.locate()
- local xDev = curX - x
- local yDev = curY - y
- local zDev = curZ - z
- if yDev+0.1 < 0 then
- local power = trim(math.abs(yDev) / 6 ,0.1)
- print(power, "down", y, curY, power, yDev)
- a.launch(0,90, power)
- end
- if yDev-0.1 > 0 then
- local power = trim(math.abs(yDev) / 6 ,0.1)
- print(power, "up", y, curY, power, yDev)
- a.launch(0,270, power)
- end
- if xDev+0.1 < 0 then
- local power = trim(math.abs(xDev) / 8 ,0.33)
- print(power, "west", x, curX, power, xDev)
- a.launch(90,0, power)
- sleep(0.1)
- a.launch(270,0, power * 0.75)
- end
- if xDev-0.1 > 0 then
- local power = trim(math.abs(xDev) / 8 ,0.33)
- print(power, "east", x, curX, power, xDev)
- a.launch(270,0, power)
- sleep(0.1)
- a.launch(90,0, power * 0.75)
- end
- if zDev+0.1 < 0 then
- local power = trim(math.abs(zDev) / 8 ,0.33)
- print(power, "north", z, curZ, power, zDev)
- a.launch(180,0, power)
- sleep(0.1)
- a.launch(0,0, power * 0.75)
- end
- if zDev-0.1 > 0 then
- local power = trim(math.abs(zDev) / 8 ,0.33)
- print(power, "south", z, curZ, power, zDev)
- a.launch(0,0, power)
- sleep(0.1)
- a.launch(180,0, power * 0.75)
- end
- end
- sleep(2)
- end
- end,
- function()
- while true do
- event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- p = false
- if message == "up" then
- curY = curY + 1
- a.launch(0,270,0.4)
- sleep(0.4)
- a.launch(0,90, 0.3)
- elseif message == "down" then
- curY = curY - 1
- a.launch(0,90, 0.4)
- sleep(0.4)
- a.launch(0,270,0.3)
- elseif message == "north" then
- curZ = curZ - 1
- a.launch(180,0, 0.15)
- sleep(0.4)
- a.launch(0,0, 0.1)
- elseif message == "south" then
- curZ = curZ + 1
- a.launch(0,0, 0.15)
- sleep(0.4)
- a.launch(180,0, 0.1)
- elseif message == "west" then
- curX = curX - 1
- a.launch(90,0, 0.15)
- sleep(0.4)
- a.launch(270,0, 0.1)
- elseif message == "east" then
- curX = curX + 1
- a.launch(270,0, 0.15)
- sleep(0.4)
- a.launch(90,0, 0.1)
- end
- p = true
- end
- end
- )
Add Comment
Please, Sign In to add comment