Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / trace

Trace

Players & world

@s2script/sdk/trace

Ray / line / hull traces returning a liveness-gated hit entity.

4 exports

Import

import { TraceMask } from "@s2script/sdk/trace";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

const
TraceMask

Named InteractionLayers bitmasks for TraceOptions.mask/exclude (bitwise-OR combinable).

readonly ShotPhysics: number
— World + player-clip + windows + players/NPCs/physics-props — a bullet trace (the default).
readonly ShotHitbox: number
— Hitboxes only (headshot-style detection).
readonly ShotFull: number
— Physics + hitboxes (a full bullet trace: world geometry AND hitbox precision).
readonly WorldOnly: number
— World geometry only, no entities at all.
readonly Grenade: number
— Grenade trajectory trace (world + physics props, no players).
readonly BrushOnly: number
— Brushes only (no clip volumes, no entities).
readonly PlayerMove: number
— Player movement collision (world + player-clip).
readonly NPCMove: number
— NPC movement collision (world + npc-clip).
interface
TraceHit

The result of a Trace.line/ray/hull call.

didHit: boolean
— True iff the trace hit something before reaching endPos.
fraction: number
— 0..1 — the fraction of the start->end segment traveled before the hit (1 = no hit).
endPos: Vector
— The trace's final position (the hit point, or the requested end on a miss).
normal: Vector
— The surface normal at the hit point ((0,0,0) on a miss).
entity: EntityRef | null
— The hit entity, or null if none was hit (or it went stale in the same frame).
startSolid: boolean
— True iff the trace STARTED embedded in solid geometry (Source startsolid; CS2's CGameTrace exposes only m_bStartInSolid, not a whole-segment allsolid flag — don't confuse with SM's TR_AllSolid).
interface
TraceOptions

Options shared by Trace.line/ray/hull.

mask?: number
— InteractionLayers bits the trace should interact with. Default TraceMask.ShotPhysics.
exclude?: number
— InteractionLayers bits to explicitly exclude. Default 0 (none).
ignoreEntity?: EntityRef
— An entity to ignore (e.g. the tracing pawn itself, for pawn.aimTrace's self-ignore).
const
Trace

Ray-tracing entry point — line/ray/hull traces over the Source 2 physics scene.

import { Trace } from "@s2script/sdk/trace";
import { Vector } from "@s2script/sdk/math";
const down = Trace.line(new Vector(o.x, o.y, o.z + 500), new Vector(o.x, o.y, o.z - 100));
if (down.didHit) console.log(down.fraction, down.endPos);
line(start: Vector, end: Vector, opts?: TraceOptions): TraceHit
— A line trace from start to end.
ray(start: Vector, angles: QAngle, distance: number, opts?: TraceOptions): TraceHit
— A line trace from start along angles' forward direction, distance units long.
hull(start: Vector, end: Vector, mins: Vector, maxs: Vector, opts?: TraceOptions): TraceHit
— A swept-box (hull) trace from start to end with the given mins/maxs extents.
Back to modules All packages