Skip to content

Instantly share code, notes, and snippets.

@mjwells2002
Created September 11, 2020 03:56
Show Gist options
  • Save mjwells2002/f61e47ff24f6236a9ff62b7326f601e8 to your computer and use it in GitHub Desktop.
Save mjwells2002/f61e47ff24f6236a9ff62b7326f601e8 to your computer and use it in GitHub Desktop.
local modules = peripheral.find("neuralInterface")
if not modules then
error("Must have a neural interface", 0)
end
if not modules.hasModule("plethora:sensor") then error("Must have a sensor", 0) end
if not modules.hasModule("plethora:scanner") then error("Must have a scanner", 0) end
if not modules.hasModule("plethora:introspection") then error("Must have an introspection module", 0) end
if not modules.hasModule("plethora:kinetic", 0) then error("Must have a kinetic agument", 0) end
local meta = {}
local hover = true
local x
local y
local z
local targetX = -327
local targetZ = -389
meta = modules.getMetaOwner()
function distance(tx,ty,x,y)
return math.abs(math.sqrt(math.pow(tx - x,2) + math.pow(ty - y,2)))
end
parallel.waitForAny(
function ()
while true do
local event, key = os.pullEvent()
if event == "key" and key == keys.l then
while true do
if math.abs(300-y) > 5 then
modules.launch(0, -90, 4)
else
break
end
end
end
end
end,
function()
while true do
local event, key = os.pullEvent()
if event == "key" and key == keys.o then
local deltaX = targetX - x;
local deltaZ = targetZ - z;
local rad = math.atan2(deltaX, deltaZ)
local deg = rad * (180 / math.pi)
while true do
deltaX = targetX - x;
deltaZ = targetZ - z;
if distance(targetX,targetZ,x,z) > 150 then
print("applying force!")
modules.launch(-deg, 0 , max(0.2,min(4,distance(targetX,targetZ,x,z)/10)))
end
break
end
end
end
end
end,
function()
while true do
meta = modules.getMetaOwner()
end
end,
function()
while true do
x,y,z = gps.locate(1)
end
end,
function()
while true do
if hover then
-- We calculate the required motion we need to take
local mY = meta.motionY
mY = (mY - 0.138) / 1.1
-- If it is sufficiently large then we fire ourselves in that direction.
if mY > 0.5 or mY < 0 then
local sign = 1
if mY < 0 then sign = -1 end
modules.launch(0, 90 * sign, math.min(4, math.abs(mY)))
else
sleep(0)
end
else
os.pullEvent("hover")
end
end
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment