ISource2ModTrace

Interface and utilities for ray tracing and collision queries.

This module provides functionality for:

  • Raycasting (line traces)
  • Hull traces (box collision)
  • Physics queries
  • Visibility and hit detection
Commonly used for shooting, line-of-sight checks and movement.

Interface for performing trace operations.

Interface id ISource2ModTrace001 (SOURCE2MOD_TRACE_INTERFACE) · Global g_pSource2ModTrace · Header source2mod/ISource2ModTrace.h

Methods

TraceShape

virtual TraceResult TraceShape(const Vector& vecStart, const QAngle& angAngles, CBaseEntity* pIgnoreEntity, TraceOptions* pTraceOptions) = 0;

Performs directional trace using angles.

ParameterType
vecStartconst Vector&
angAnglesconst QAngle&
pIgnoreEntityCBaseEntity*
pTraceOptionsTraceOptions*

TraceEndShape

virtual TraceResult TraceEndShape(const Vector& vecStart, const Vector& vecEnd, CBaseEntity* pIgnoreEntity, TraceOptions* pTraceOptions) = 0;

Performs trace between two points.

ParameterType
vecStartconst Vector&
vecEndconst Vector&
pIgnoreEntityCBaseEntity*
pTraceOptionsTraceOptions*

TraceHullShape

virtual TraceResult TraceHullShape(const Vector& vecStart, const Vector& vecEnd, const Vector& vecMins, const Vector& vecMaxs, CBaseEntity* pIgnoreEntity, TraceOptions* pTraceOptions) = 0;

Performs hull (box) trace.

ParameterType
vecStartconst Vector&
vecEndconst Vector&
vecMinsconst Vector&
vecMaxsconst Vector&
pIgnoreEntityCBaseEntity*
pTraceOptionsTraceOptions*

TraceShapeEx

virtual TraceResult TraceShapeEx(const Vector& vecStart, const Vector& vecEnd, CTraceFilter* pTraceFilter, Ray_t* pRay) = 0;

Advanced trace with custom filter.

ParameterType
vecStartconst Vector&
vecEndconst Vector&
pTraceFilterCTraceFilter*
pRayRay_t*

PointContents

virtual uint64 PointContents(const Vector* const vTestPos, uint64 nContentsMask) = 0;

Returns the contents bitmask at a world position.

ParameterType
vTestPosconst Vector* const
nContentsMaskuint64

CheckAreaOverlappingEntity

virtual bool CheckAreaOverlappingEntity(const CCSNavArea* const rArea, const CBaseEntity* const rEntity, bool bExtrudeHullHeight) = 0;

Checks whether a nav area overlaps with an entity.

ParameterType
rAreaconst CCSNavArea* const
rEntityconst CBaseEntity* const
bExtrudeHullHeightbool

GetEntityWorldSpaceAABB

virtual void GetEntityWorldSpaceAABB(const CBaseEntity* const rEntity, Vector* pMinsOut, Vector* pMaxsOut) = 0;

Retrieves the world-space AABB of an entity.

ParameterType
rEntityconst CBaseEntity* const
pMinsOutVector*
pMaxsOutVector*

CTraceFilterEx

The filter TraceShapeEx expects when you have an entity to ignore.

Source2Mod uses this one internally; it is here because a plugin calling TraceShapeEx needs a CTraceFilter of its own and this covers the ordinary case -- ignore an entity, its owner and everything sharing its hierarchy.

Inherits CTraceFilter

Constructors

explicit CTraceFilterEx(CBaseEntity* pEntityToIgnore);
CTraceFilterEx();

TraceOptions

Options controlling trace behavior.

Fields

FieldType
InteractsAsuint64_t
InteractsWithuint64_t
InteractsExcludeuint64_t

TraceResult

Result of a trace query.

Contains information about collision, hit entity, hit position, surface data, and more.

Constructors

TraceResult();
explicit TraceResult(const CGameTrace* pTrace);
TraceResult(const TraceResult&) = delete;
TraceResult(TraceResult&&) = default;

StartPos

const Vector& StartPos() const;

EndPos

const Vector& EndPos() const;

HitPoint

const Vector& HitPoint() const;

Normal

const Vector& Normal() const;

Fraction

float Fraction() const;

HitOffset

float HitOffset() const;

DidHit

bool DidHit() const;

IsAllSolid

bool IsAllSolid() const;

HasExactHit

bool HasExactHit() const;

HitEntity

CEntityInstance* HitEntity() const;

TriangleIndex

int TriangleIndex() const;

HitboxBoneIndex

int HitboxBoneIndex() const;

Hitbox

CHitBox* Hitbox() const;

Contents

int Contents() const;

RayType

RayType_t RayType() const;

Body

IPhysicsBody* Body() const;

Shape

IPhysicsShape* Shape() const;

BodyTransform

const CTransform& BodyTransform() const;

ShapeAttributes

const RnCollisionAttr_t& ShapeAttributes() const;

Surface

CPhysSurfaceProperties* Surface() const;

Macros

MacroExpands to
TRACE_SHAPE(start, angles, ent, opts)g_pSource2ModTrace->TraceShape(start, angles, ent, opts)
TRACE_END_SHAPE(start, end, ent, opts)g_pSource2ModTrace->TraceEndShape(start, end, ent, opts)
TRACE_HULL_SHAPE(start, end, mins, maxs, ent, opts)g_pSource2ModTrace->TraceHullShape(start, end, mins, maxs, ent, opts)
TRACE_SHAPE_EX(start, end, filter, ray)g_pSource2ModTrace->TraceShapeEx(start, end, filter, ray)
POINT_CONTENTS(pos, mask)g_pSource2ModTrace->PointContents(pos, mask)
ENTITY_WORLD_AABB(ent, mins, maxs)g_pSource2ModTrace->GetEntityWorldSpaceAABB(ent, mins, maxs)
CHECK_AREA_OVERLAPPING_ENTITY(area, ent, extrudeHull)g_pSource2ModTrace->CheckAreaOverlappingEntity(area, ent, extrudeHull)

On this page