LineTrace

From ZDoom Wiki
Jump to: navigation, search

bool LineTrace (double angle, double distance, double pitch[, int flags = 0[, double offsetz = 0.[, double offsetforward = 0.[, double offsetside = 0.[, out FLineTraceData data = null]]]]])

Usage

Draws a hitscan line at the specified angle, pitch and range (distance). The line originates from the calling actor's exact position, which means that offsetz must be used if this is intended to represent an attack like a gunshot.

Return value

The function's actual return is true or false, indicating whether the line hit anything.

Much more significantly, this function lets you write information to an FLineTraceData pointer that can be accessed for detailed information about what the line hit and where.

The struct contains the following pointers:

  • AActor *HitActor: the actor that got hit, if any.
  • line_t *HitLine: the line that got hit, if any.
  • sector_t *HitSector: the sector in which the impact occurred or the line terminated.
  • F3DFloor *Hit3DFloor: (Need more info)
  • FTextureID HitTexture: the texture that got hit, if any.
  • DVector3 HitLocation: the spot in which the impact occurred or the line terminated.
  • DVector3 HitDir: a 1-unit-long vector3 representing the direction in which the line came out.
  • double Distance: the length of the final line formed, whether it hit anything or not.
  • int NumPortals: (Need more info)
  • int LineSide: (Need more info)
  • int LinePart: (Need more info)
  • int SectorPlane: (Need more info)
  • ETraceResult HitType: one of the following constants, which are pretty self-explanatory:
  • TRACE_HitNone
  • TRACE_HitFloor
  • TRACE_HitCeiling
  • TRACE_HitWall
  • TRACE_HitActor
  • TRACE_CrossingPortal

Flags

  • TRF_ABSPOSITION(Need more info)
  • TRF_ABSOFFSET (Need more info)
  • TRF_THRUSPECIES — passes through all actors of a given species.
  • TRF_THRUACTORS — passes through all actors. Useful for when you only need map geometry.
  • TRF_THRUBLOCK — passes through all lines set to "block everything".
  • TRF_THRUHITSCAN — passes through all lines set to block hitscans.
  • TRF_NOSKY — treats hitting a sky texture as not hitting anything at all.
  • TRF_ALLACTORS(Need more info)

Examples

This item when used will hit any switch in front of the player within about 50 metres, provided nothing is between the player and the line.

class RemoteSwitcher : CustomInventory
{
    States
    {
    Use:
        TNT1 A 0
        {
            FLineTraceData RemoteRay;
            LineTrace(
               angle,
               2048,
               pitch,
               offsetz: height-12,
               data: RemoteRay
            );

            if (RemoteRay.HitType == TRACE_HitWall)
            {
               RemoteRay.HitLine.Activate(self, 0, SPAC_Use);
            }
        }
        Fail;
    }
}