Skip to content

Raycast hit table

Returned by world:raycast, world:raycast_entity and player:raycast. Check type to see what was hit — player:raycast can return either kind.

Every hit

Field Meaning
type "block" or "entity"
pos Exact hit point as vec3
distance Distance from ray start to hit

Block hits (type == "block")

Field Meaning
block_pos Hit block position as vec3
side Hit face: "up", "down", "north", "south", "east", "west"
inside true if the ray started inside the block
state Block state handle of the hit block

Entity hits (type == "entity")

Field Meaning
entity Entity handle of the hit entity
local hit = player:raycast(20)
if hit then
    if hit.type == "entity" then
        print("looking at " .. hit.entity:name())
    else
        print("looking at " .. hit.state:name() .. " (" .. hit.side .. ")")
    end
end
Navigation

Type to search…

↑↓ navigate↵ selectEsc close