The block-based camera component is a fixed rangefinder from Computronics. It measures the distance to the first solid block hit by a ray projected from the camera block's facing direction.
Compared with the robot version, this block variant only scans forward, but it is useful as a mounted sensor in doors, hallways, docking stations, and automation lines.
- Repository:
computronics - Component name:
camera - Typical host: placed Computronics camera block
local component = require("component")
local camera = component.camera
if not camera then
error("camera component not installed")
endYou can also access a specific device with component.proxy(address).
- The default maximum range is
32blocks. - Optional
xandyoffsets adjust the ray within the camera view. - Each offset must stay in the range
-1.0to1.0. - If no block is hit within range, the method returns
-1.
The block always scans along its placed facing direction.
- Syntax:
camera.distance([x, y]) - Returns:
number - Purpose: Returns the distance to the first block hit by the camera.
Parameters:
x:numberoptional: horizontal view offset.y:numberoptional: vertical view offset.
Behavior:
- With no arguments, the camera scans straight forward.
- If either offset lies outside
-1.0to1.0, the method returns-1. - If no block is hit within range, the method returns
-1.
Example:
local d = camera.distance()
if d >= 0 then
print("Detected block at", d, "blocks")
else
print("Nothing detected in range")
endExample: sample slightly above center.
print("Upper view distance:", camera.distance(0.0, -0.35))- This component measures blocks, not entities.
- In environments where the camera also drives redstone output refresh, the redstone side behavior is separate from the Lua callback and does not change the return format of
distance().
componentradar