Advertisement
osmarks

laser-sweep

Jun 11th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. local laser = peripheral.wrap "right"
  2. local yaw = tonumber(... or 0)
  3. local blocksRemovedPerShot = 2
  4.  
  5. local function fmt2dp(x)
  6.     return ("%.2f"):format(x)
  7. end
  8.  
  9. local function shootBlock(depth, forward)
  10.     -- HERE BE TRIGONOMETRY
  11.     local firingAngle = math.atan(depth / forward)
  12.     local distanceToTarget = depth / math.sin(firingAngle)
  13.     for i = 0, math.floor(distanceToTarget / blocksRemovedPerShot) do
  14.         print("DIST", fmt2dp(distanceToTarget), "ANGL", fmt2dp(math.deg(firingAngle)), "DPTH", fmt2dp(depth), "FRWD", fmt2dp(forward))
  15.         laser.fire(yaw, math.deg(firingAngle), 5)
  16.     end
  17. end
  18.  
  19. for depth = 0, 64 do
  20.     shootBlock(depth, 16)
  21. end
  22.  
  23. for forward = 16, 0, -1 do
  24.     shootBlock(64, forward)
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement