3F0xog

ew

Dec 8th, 2023
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | Gaming | 0 0
  1. --setup
  2. local reader = peripheral.find("ship_reader")
  3. local helm = peripheral.find("ship_helm")
  4. function sign(number)
  5.     return number > 0 and 1 or (number == 0 and 0 or -1)
  6. end    
  7. function getYaw()
  8.     rot = reader.getRotation(true)
  9.     shipYaw = math.atan2(2*rot.y*rot.w-2*rot.x*rot.z,1-2*rot.y*rot.y-2*rot.z*rot.z )
  10.     return shipYaw
  11. end
  12.  
  13. local detector = peripheral.find("playerDetector")
  14. helm.move("forward",true)
  15. --loop start
  16. while true do
  17.     --get player position
  18.     local player = detector.getPlayerPos("3F0x")
  19.     --get ship position
  20.     local shipPosition = reader.getWorldspacePosition()
  21.     --get ship rotation
  22.     local shipRot = reader.getRotation()
  23.     --get current yaw direction
  24.     local shipYaw = getYaw()*(180/3.14159)
  25.     if sign(shipYaw) == -1 then
  26.     shipYaw = 360 +  shipYaw
  27.     end    
  28.       --get ideal yaw direction
  29.     local  idealYaw =  360
  30.     local idealYawX = 360
  31.     local idealYawz = 360    
  32.     if shipPosition.x < player.x then
  33.       idealYawX = 160  
  34.      elseif shipPosition.x >  player.x then
  35.          idealYawX =  340  
  36.      end
  37.      if shipPosition.z < player.z then
  38.      idealYawZ = 70
  39.      elseif shipPosition.z > player.z then
  40.      idealYawZ = 250
  41.      end
  42.      idealYaw = (idealYawX + idealYawZ) / 2
  43.      if idealYawX == 340 and idealYawZ == 70 then
  44.          idealYaw =  25
  45.      end
  46.      print("ideal: "..idealYaw.. " idealX: "..idealYawX.. "idealz:  ".. idealYawZ )
  47.    
  48.     local d1 = "left"
  49.     local d2 = "right"
  50.  
  51.      if  shipYaw   <   idealYaw then
  52.     helm.move(d1,true)
  53.     else
  54.     helm.move(d2  ,true)
  55.     end
  56.     print("Yaw ".. shipYaw )
  57.     -- helm.move("left",true)      
  58.      
  59.      
  60. end
Advertisement
Add Comment
Please, Sign In to add comment