Skip to content

Tracelines

GeckoN edited this page Mar 29, 2017 · 5 revisions

Tracelines are used to perform hit detection, which is handled by the engine. It is one of the primary means of handling navigation and hit detection in the game.

TraceResult

The TraceResult class stores trace results. Not all trace operations require the use of a TraceResult object.

Properties

Variable Description
int fAllSolid Flag telling whether the trace started and ended in a solid area. If true, the plane is not valid.
int fStartSolid Flag telling whether the trace started in a solid area.
int fInOpen Flag telling whether the trace ended in empty space.
int fInWater Flag telling whether the trace ended in water.
float flFraction How much of the trace's total distance was covered. 1.0 means it didn't hit anything.
Vector vecEndPos End position. If flFraction is 1.0, this is invalid.
float flPlaneDist Brush plane distance. This appears to be the dot product between the first plane point and the normal. Its purpose is unknown, and there are no known uses. If flFraction is 1.0, this is invalid. If the hit object is not a brush, this is invalid.
Vector vecPlaneNormal Brush plane normal. If flFraction is 1.0, this is invalid. If the hit object is not a brush, this is invalid.
edict_t@ pHit Hit entity. If flFraction is 1.0, this is null.
int iHitgroup Studio model hit group. if flFraction is 1.0, this is invalid. If the hit object is not a studio model, this is invalid.

Supported trace operations

There are a number of traces that can be performed:

Operation Description Bounds
void TraceLine(const Vector& in vecStart, const Vector& in vecEnd, IGNORE_MONSTERS igmon, edict_t@ pEntIgnore, TraceResult& out ptr) Calculates a trace along the given line, storing the results in ptr. If igmon is ignore_monsters, entities with a solid setting other than SOLID_BSP and a movetype other than MOVETYPE_PUSHSTEP (pushables) are ignored. If pEntIgnore is set, the entity will not be considered in traceline calculations. Uses point based bounds (zeroed out mins and maxs)
void TraceLine(const Vector& in vecStart, const Vector& in vecEnd, IGNORE_MONSTERS igmon, IGNORE_GLASS ignoreGlass, edict_t@ pEntIgnore, TraceResult& out ptr) Same as the above function, but also allows you to specify whether or not to ignore glass. If ignore_glass is specified, brush entities with a render mode other than normal and that don't have the FL_WORLDBRUSH flag set are ignored. Uses point based bounds (zeroed out mins and maxs)
void TraceHull(const Vector& in vecStart, const Vector& in vecEnd, IGNORE_MONSTERS igmon, HULL_NUMBER hullNumber, edict_t@ pEntIgnore, TraceResult& out ptr) Similar to TraceLine, but will use the specified hull's bounds instead of point based bounds. Uses the specified hull's bounds. Maps can specify these bounds in newer compilers, so avoid assuming a particular value is in use.
void TraceToss(edict_t@ pEntity, edict_t@ pEntityToIgnore, TraceResult& out traceResult) Traces a toss. This simulates tossing the entity using its current origin, velocity, angular velocity, angles and gravity. Note that this does not use the same code as MOVETYPE_TOSS, and may return different results. Uses the given entity's bounds.
bool TraceMonsterHull(edict_t@ pEntity, const Vector& in vecStart, const Vector& in vecEnd, IGNORE_MONSTERS igmon, edict_t@ pEntityToIgnore, TraceResult& out ptr) Performs a trace using the given entity's mins and maxs. This can be any entity, not just monsters. Returns true if the trace was entirely in a solid object, or if it hit something. Uses the given entity's bounds.
void TraceModel(const Vector& in vecStart, const Vector& in vecEnd, int iHullNumber, edict_t@ pEntityToIgnore, TraceResult& out ptr) Similar to TraceHull, but will instead perform a trace in the given world hull using the given entity's model's hulls. For studio models this will use the model's hitboxes. If the given entity's model is a studio model, uses its hitboxes. If it's a brush model, the brush model's hull for the given hull number is used (this may differ if custom brush hull sizes are in use). Otherwise, the entity bounds are converted into a hull.
string TraceTexture(edict_t@ pEntity, const Vector& in vecStart, const Vector& in vecEnd) Used to get the name of a texture. The given entity must have a brush model set. If the traceline intersects the model, the name of the texture of the surface it intersected is returned. Otherwise, returns an empty string. Uses point based bounds (zeroed out mins and maxs)

IGNORE_MONSTERS enum

Constant Purpose
dont_ignore_monsters Don't ignore monsters.
ignore_monsters Ignore monsters.
missile The traceline bounds are set to mins -15, -15, -15 and maxs 15, 15, 15. Otherwise, the bounds are specified by the traceline operation.

IGNORE_GLASS enum

Constant Purpose
dont_ignore_glass Don't ignore glass.
ignore_glass Ignore glass.

HULL_NUMBER enum

Constant Hull # Default Mins Default Maxs Default Size
point_hull 0 0, 0, 0 0, 0, 0 0x0x0
human_hull 1 -16, -16, -36 16, 16, 36 32x32x72
large_hull 2 -32, -32, -32 32, 32, 32 64x64x64
head_hull 3 -16, -16, -18 16, 16, 18 32x32x36
Clone this wiki locally