Skip to content

HitResult

Represents the result of a raycast or similar action, containing details about the position and the type of object hit.

Example: What do you look at?

local hit = spell.owner:raycast(16)
if not hit then
  print("Nothing in reach")
elseif hit.type == "entity" then
  ---@cast hit EntityHitResult
  print("An entity: " .. hit.entity.name)
else
  ---@cast hit BlockHitResult
  spell.pos = hit.blockPos
  print("A block: " .. spell.block.type.name)
end

Fields

pos: Vec3 — Read-Only

A copy of the position where the hit occurred.

type: HitType — Read-Only

What was hit.