local function yaw_pitch(xoff,yoff,zoff) local yaw = -math.deg(math.atan2(xoff,zoff)) local perp_dist = math.sqrt(xoff*xoff+zoff*zoff) local pitch = -math.deg(math.atan2(yoff, perp_dist)) return yaw,pitch end local scanner = assert(peripheral.wrap"right") local laser = assert(peripheral.wrap"left") while true do local targets = {} local scanned = scanner.scan() for _,v in ipairs(scanned) do if v.z <= 7 and v.z >= -8 and v.x <= 7 and v.x >= -8 and v.y < 0 then local yaw,pitch = yaw_pitch(t.x,t.y,t.z) laser.fire(yaw,pitch,4) end end until #targets == 0