TraceRes

From GMod Wiki

(Redirected from Trace result table)
Jump to: navigation, search
Structure
Name TraceRes
Available On: NewerShared.png
Description:
The results of a trace are contained in the structure of this table.

Members

Name Type Description
Entity Entity Returns the entity the trace hit. Use Entity:IsWorld() to check if you hit the world.
Fraction Float This is a number between 0 and 1. Ex. 0.01 = 1/100 of your tracer's max range.
FractionLeftSolid Float If the trace starts in a solid, this describes when the trace leaves it as a fraction of the trace distance.
Hit Boolean Returns true if the trace hits something, false if it stops dead in the air.
HitBox Integer Appears to be an alias of HitGroup.
HitGroup Integer Number that corresponds with a hitgroup enumeration.
HitNoDraw Boolean Returns true if the trace hit a no-draw brush in the world.
HitNonWorld Boolean This is true if anything other than the world was hit - this can be used for detecting entities.
HitNormal Vector This is a normalized vector that is perpendicular to the surface you hit. This is used, for example, when right-clicking with rope-based constraints.
HitPos Vector This is a vector that describes the X, Y, Z position the trace hit in the world. If the trace didn't hit anything, this will be the maximum length of the trace.
HitSky Boolean If the trace hits the sky, this returns true.
HitTexture String This is the texture that the trace hit. Returns "**studio**" if it hits an entity or player, "**empty**" if the trace hits nothing, "**displacement**" if the trace hits a displacement surface.
HitWorld Boolean If the trace hits the world, returns true. If it hits an entity, returns false.
MatType Integer This is a number that corresponds with a material enumeration. It describes the type of material you hit. NOTE; Metrocop heads have an unlisted enumeration number of 45.
Normal Vector Equivalent to (traceRes.HitPos - traceRes.StartPos):Normalize(). This vector points in the direction the trace traveled from start to finish.
PhysicsBone Integer This is the ID number of the physics bone in a ragdoll. This is 0 in all cases not dealing with ragdolls.
StartPos Vector This is a vector representing the X, Y, Z position the trace started at.
StartSolid Boolean Indicates if the trace started within a solid, such as a brush or a player.

Examples

DescriptionDo a trace from the player's eyes and get something from the structure
Used onNewerShared.png
Code
 
local pl = player.GetByID(1)
local traceRes = pl:GetEyeTrace()
if traceRes.HitWorld then
    Msg("Hit world!\n")
else
    Msg("Didn't hit world!\n")
end
 
Output"Hit world!" or "Didn't hit world!" in console


DescriptionShow the TraceRes table (all information in the TraceRes)
Used onNewerShared.png
Code
PrintTable(util.TraceLine({start=Vector(0,0,123), endpos=Vector(0,0,-2)}))
Output
FractionLeftSolid = 0
HitNonWorld       = false
Fraction          = 0.99175006151199
Entity            = Entity [0][worldspawn]
HitNoDraw         = false
HitSky            = false
HitPos            = 0.0000 0.0000 -0.9688
StartSolid        = false
HitWorld          = true
HitNormal         = 0.0000 0.0000 1.0000
HitBox            = 0
Normal            = 0.0000 0.0000 -1.0000
Hit               = true
HitGroup          = 0
MatType           = 68
StartPos          = 0.0000 0.0000 123.0000
PhysicsBone       = 0
(On gm_flatgrass)


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox