MegiRicky

ciwsOnboardNGDW

Aug 3rd, 2024 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local reader = peripheral.find("blockReader")
  3.  
  4. redstone.setOutput("back",false)
  5. local cannonHitPosChannel = nil
  6. print("Input the channel you want to use, default: 700")
  7. cannonHitPosChannel = io.read()
  8. if cannonHitPosChannel == "" then
  9. cannonHitPosChannel = 700
  10. end
  11. cannonHitPosChannel = tonumber(cannonHitPosChannel)
  12.  
  13. if modem then
  14. modem.open(cannonHitPosChannel)
  15. end
  16.  
  17. if not reader then
  18. print("No blockReader found.")
  19. end
  20.  
  21. local distance = 100
  22.  
  23. --Main loop
  24. while true do
  25. redstone.setOutput("back",true)
  26. local hitPos = {}
  27. local sourceData = {}
  28.  
  29. if reader then
  30. cannonData = reader.getBlockData()
  31. cannonPitch = cannonData.CannonPitch
  32. else
  33. cannonPitch = 0
  34. end
  35.  
  36. local source = ship.getWorldspacePosition()
  37. local sourceX, sourceY, sourceZ = source.x, source.y, source.z
  38.  
  39. local yaw = math.deg(ship.getYaw()) + 90
  40.  
  41. local shipPitch = math.deg(ship.getRoll())
  42. local shipRoll = math.deg(ship.getPitch())
  43. print("cannonPitch: "..cannonPitch)
  44. print(" shipPitch: "..shipPitch)
  45. print("shipRoll: "..shipRoll)
  46. local pitch = cannonPitch * math.sin(math.rad(90-shipRoll)) + shipPitch
  47. local yawAdjust = cannonPitch * math.cos(math.rad(90 - shipRoll))
  48. print("yawAd: "..yawAdjust)
  49. if shipRoll < 0 then
  50. yaw = yaw + math.abs(yawAdjust)
  51. else
  52. yaw = yaw - math.abs(yawAdjust)
  53. end
  54. if yaw > 360 then yaw = yaw - 360 end
  55. if yaw < 0 then yaw = yaw + 360 end
  56. local yawRad = math.rad(yaw)
  57. local pitchRad = math.rad(pitch)
  58.  
  59. local dx = distance * math.cos(pitchRad) * math.sin(yawRad)
  60. local dz = -distance * math.cos(pitchRad) * math.cos(yawRad)
  61. local dy = distance * math.sin(pitchRad)
  62.  
  63. local targetX = sourceX + dx
  64. local targetY = sourceY + dy
  65. local targetZ = sourceZ + dz
  66.  
  67. print("targetX: "..targetX.." targetY: "..targetY.." targetZ: "..targetZ)
  68.  
  69. print(" pitch: "..pitch)
  70. print(" yaw: "..yaw)
  71.  
  72. table.insert(sourceData, 1, targetX)
  73. table.insert(sourceData, 2, targetY)
  74. table.insert(sourceData, 3, targetZ)
  75. table.insert(sourceData, 4, "coordinate")
  76. table.insert(sourceData, 5, source)
  77. table.insert(sourceData, 6, pitch)
  78. table.insert(sourceData, 7, yaw)
  79. modem.transmit(cannonHitPosChannel,0,sourceData)
  80.  
  81. sleep()
  82. end
Advertisement
Add Comment
Please, Sign In to add comment