Trace

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


LineTracer

native bool Trace(vector3 start, Sector sec, vector3 direction, double maxDist, ETraceFlags traceFlags)

Usage

Starts a trace from the given start spot that travels in the given direction. This will report any Actor in the blockmap it hits, any line it hits, and any plane it hits. See TraceCallback for how to handle the information this function retrieves. Important to note is that this class does not know who it "belongs" to. If ignoring certain Actors is desired, this will have to be handled manually within TraceCallback().

Parameters

  • start - The starting location of the trace. This is an absolute map coordinate
  • sec - The sector that the trace is starting from
  • direction - A 3D vector that points in the direction the trace should start traveling
  • maxDist - How far the trace should travel before it terminates
  • traceFlags - Modifies the behavior of the trace
  • TRACE_NoSky - Hitting the sky sets the HitType to TRACE_HitNone
  • TRACE_PortalRestrict - Cannot travel through portals that are not linked
  • TRACE_ReportPortals - Update Results to accurately reflect traveling through a portal. TraceCallback() is called with a HitType of TRACE_CrossingPortal when traveling through one
  • TRACE_HitSky - Hitting the sky sets the HitType to TRACE_HasHitSky

Return value

Returns true if the trace hit anything (Results' HitType is not TRACE_HitNone). Returns false otherwise.

Examples

void A_FindGhosts()
{
    // Create the tracer
    let tracer = new("GhostFinder");
    if (!tracer)
        return;

    // Get the current direction the player is looking
    Vector3 dir = (AngleToVector(angle, cos(pitch)), -sin(pitch));

    // Set the starting point to the player's position + 3/4 their height
    Vector3 start = pos + (0,0,height*3/4);

    tracer.Trace(start, CurSector, dir, PLAYERMISSILERANGE, 0);
    if (tracer.bHitGhost)
        console.printf("Ahhh! A spooky ghost!");
}