Silasko

Turtle GetHeading

May 7th, 2022 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local north,south,east,west = 0
  2. function getHeading()
  3.     local x,y,z = gps.locate()
  4.     print("Getting Turtle heading...")
  5.     --move 1 block forward / dig and move forward
  6.     if(turtle.detect() == true) then
  7.         turtle.dig()
  8.         turtle.forward()
  9.     else
  10.         turtle.forward()
  11.     end
  12.     local newX,newY,newZ = gps.locate()
  13.     if newX == x then
  14.         if newZ > z then
  15.             print("Facing South")
  16.             south = 1
  17.         else
  18.             print("Facing North")
  19.             north = 1
  20.         end
  21.     else
  22.         if newX > x then
  23.             print("Facing East")
  24.             east = 1
  25.         else
  26.             print("Facing West")
  27.             west = 1
  28.         end
  29.     end
  30.     faceNorth()
  31. end
  32.  
  33. function faceNorth()
  34.     if north == 1 then
  35.         print("Facing North already..")
  36.     end
  37.     if south == 1 then
  38.         turtle.turnRight()
  39.         turtle.turnRight()
  40.     end
  41.     if east == 1 then
  42.         turtle.turnLeft()
  43.     end
  44.     if west == 1 then
  45.         turtle.turnRight()
  46.     end
  47. end
  48.  
  49. getHeading()
Add Comment
Please, Sign In to add comment