Advertisement
jaklsfjlsak

GPT 三维激光定位

Apr 14th, 2025
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. local ship = peripheral.find("warpdriveShipCore")
  2. local lasers = peripheral.getNames()
  3.  
  4. local offsetDistance = 18
  5.  
  6. for i = #lasers, 1, -1 do
  7.     if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
  8.         table.remove(lasers, i)
  9.     else
  10.         peripheral.wrap(lasers[i]).beamFrequency(1420)
  11.     end
  12. end
  13.  
  14. ship_front, ship_right, ship_up = ship.dim_positive()
  15. ship_back, ship_left, ship_down = ship.dim_negative()
  16. ship_isInHyper = ship.isInHyperspace()
  17. ship_movement = { ship.movement() }
  18. ship_rotationSteps = ship.rotationSteps()
  19.  
  20. print("Emit Scanning Laser to Jump Ship and Aligning the Mining Laser")
  21.  
  22. while true do
  23.     local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
  24.  
  25.     if event == "laserScanning" then
  26.         -- Convert the laser scanning coordinates to numbers and store them
  27.         local lastLx = tonumber(lx)
  28.         local lastLy = tonumber(ly)
  29.         local lastLz = tonumber(lz)
  30.        
  31.         -- Get current ship position from the ship core.
  32.         local mx, my, mz = ship.getLocalPosition()
  33.        
  34.         print("Laser target: X:" .. lastLx .. " Y:" .. lastLy .. " Z:" .. lastLz)
  35.         print("Ship current position: X:" .. mx .. " Y:" .. my .. " Z:" .. mz)
  36.        
  37.         -- Calculate the vector from laser target (L) to ship (M)
  38.         local vx = mx - lastLx
  39.         local vy = my - lastLy
  40.         local vz = mz - lastLz
  41.        
  42.         local dist = math.sqrt(vx * vx + vy * vy + vz * vz)
  43.        
  44.         if dist > 0 then
  45.             -- Normalize the vector.
  46.             local ux = vx / dist
  47.             local uy = vy / dist
  48.             local uz = vz / dist
  49.  
  50.             -- Calculate dx, dy, dz as the point offsetDistance away from the laser target along the vector toward the ship.
  51.             local dx = lastLx + ux * offsetDistance
  52.             local dy = lastLy + uy * offsetDistance
  53.             local dz = lastLz + uz * offsetDistance
  54.            
  55.             -- Round the coordinates to whole numbers.
  56.             dx = math.floor(dx + 0.5)
  57.             dy = math.floor(dy + 0.5)
  58.             dz = math.floor(dz + 0.5)
  59.            
  60.             print("Calculated jump coordinates: (" .. dx .. ", " .. dy .. ", " .. dz .. ")")
  61.         else
  62.             print("Error: The ship and the laser target are at the same location!")
  63.         end
  64.     end
  65. end
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement