trace
World traces through the game's physics query: trace.line, trace.shape and trace.bullet.
World traces through the game's own physics query. Every function costs one engine trace and must run on the game thread, from a callback or top-level script code; call them only while in game.
trace.line
trace.line(from, to, filter?)Traces a line (a ray with no extent) from from to to. filter is a trace_filter_t. Without it, the line uses the game's world filter for its own melee line trace: MASK_SOLID (0xC3001: world, windows and player hulls, no hitboxes), collision group COLLISION_GROUP_DEFAULT and every object set, with no entity skipped.
Returns: trace_t.
local eye = pawn:origin() + vector(0, 0, 64)
local tr = trace.line(eye, eye + vector(0, 0, -200))
if tr:did_hit() then print('ground at', tr.end_pos) endtrace.shape
trace.shape(ray, from, to, filter)Casts a ray_t between 3D positions with a trace_filter_t.
Returns: trace_t.
local hull = ray_t(vector(-16, -16, 0), vector(16, 16, 72))
local tr = trace.shape(hull, from, to, trace_filter_t(0xC3001, 4, true))
print(tr.fraction)trace.bullet
trace.bullet(entity, from, to)Simulates a bullet from the entity's current weapon, including penetration.
Returns: damage to the first player hitbox hit, or nil.
local damage = trace.bullet(local_pawn, eye, enemy:hitbox(0):center())
if damage then print('head damage', damage) end