Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ship = peripheral.find("warpdriveShipCore")
- local lasers = peripheral.getNames()
- local offsetDistance = 18
- for i = #lasers, 1, -1 do
- if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
- table.remove(lasers, i)
- else
- peripheral.wrap(lasers[i]).beamFrequency(1420)
- end
- end
- ship_front, ship_right, ship_up = ship.dim_positive()
- ship_back, ship_left, ship_down = ship.dim_negative()
- ship_isInHyper = ship.isInHyperspace()
- ship_movement = { ship.movement() }
- ship_rotationSteps = ship.rotationSteps()
- print("Emit Scanning Laser to Jump Ship and Aligning the Mining Laser")
- while true do
- local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
- if event == "laserScanning" then
- -- Convert the laser scanning coordinates to numbers and store them
- local lastLx = tonumber(lx)
- local lastLy = tonumber(ly)
- local lastLz = tonumber(lz)
- -- Get current ship position from the ship core.
- local mx, my, mz = ship.getLocalPosition()
- print("Laser target: X:" .. lastLx .. " Y:" .. lastLy .. " Z:" .. lastLz)
- print("Ship current position: X:" .. mx .. " Y:" .. my .. " Z:" .. mz)
- -- Calculate the vector from laser target (L) to ship (M)
- local vx = mx - lastLx
- local vy = my - lastLy
- local vz = mz - lastLz
- local dist = math.sqrt(vx * vx + vy * vy + vz * vz)
- if dist > 0 then
- -- Normalize the vector.
- local ux = vx / dist
- local uy = vy / dist
- local uz = vz / dist
- -- Calculate dx, dy, dz as the point offsetDistance away from the laser target along the vector toward the ship.
- local dx = lastLx + ux * offsetDistance
- local dy = lastLy + uy * offsetDistance
- local dz = lastLz + uz * offsetDistance
- -- Round the coordinates to whole numbers.
- dx = math.floor(dx + 0.5)
- dy = math.floor(dy + 0.5)
- dz = math.floor(dz + 0.5)
- print("Calculated jump coordinates: (" .. dx .. ", " .. dy .. ", " .. dz .. ")")
- else
- print("Error: The ship and the laser target are at the same location!")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement