Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- cx = args[1]
- cy = args[2]
- cz = args[3]
- x, y, z = gps.locate(3)
- local floor = true
- print(x, y, z)
- print(cx-x, cy-y, cz-z)
- function getAltitude()
- if floor then
- for i=1, 15 do
- turtle.up()
- end
- floor = false
- testDirection()
- else
- for i=1, 15 do
- turtle.down()
- end
- end
- end
- function checkX()
- x,y,z = gps.locate(3)
- x2 = cx-x
- print(x2)
- if x2 < 0 then
- print("want west [4]")
- face(4)
- print("next step")
- elseif x2 > 0 then
- print("want east [2]")
- face(2)
- end
- print("movin son")
- for i=1, math.abs(x2) do
- turtle.forward()
- end
- checkZ()
- end
- function checkY()
- x, y, z = gps.locate()
- y2 = cy - y
- for i=1, math.abs(y2) do
- if y2 > 0 then
- turtle.up()
- else
- turtle.down()
- end
- end
- end
- function checkZ()
- x, y, z = gps.locate(3)
- z2 = cz - z
- if z2 < 0 then
- face(1)
- elseif z2 > 0 then
- face(3)
- end
- print("MOVING")
- for i=1, math.abs(z2) do
- turtle.forward()
- end
- print("IM HERE!")
- checkY()
- end
- function testDirection()
- turtle.forward()
- x2, y2, z2 = gps.locate(3)
- x3 = x2-x
- y3 = y2-y
- z3 = z2-z
- print(x3, y3, z3)
- if x3 == 1 then
- direction = 2 --east
- elseif x3 == -1 then
- direction = 4 --west
- end
- if z3 == 1 then
- direction = 3 --south
- elseif z3 == -1 then
- direction = 1 --north
- end
- print("Facing:",direction)
- checkX()
- end
- function face(dir)
- while direction ~= dir do
- turtle.turnRight()
- direction = direction + 1
- if direction == 5 then
- direction = 1
- end
- print(direction)
- sleep(1)
- end
- return
- end
- getAltitude()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement