tr:DidHit():booleanWhether the trace hit a surface.
Ray and hull trace results — hits, fractions, planes.
tr:DidHit():booleanWhether the trace hit a surface.
tr:DidHitEntity():booleanWhether the trace hit an entity.
tr:GetStartPos():Vector3Start position of the trace.
tr:GetEndPos():Vector3End position of the trace.
tr:GetFraction():numberFraction of the trace travelled.
tr:GetHitbox():numberHitbox index that was hit.
tr:GetEntity():EntityEntity hit by the trace.
fraction:numberpropFraction travelled as a field.
entity:EntitypropHit entity as a field.
plane:Vector3propHit plane normal.
contents:numberpropContents mask at the end point.
hitbox:numberpropHitbox index as a field.
hitgroup:numberpropHitgroup that was hit.
allsolid:booleanpropWhether the trace started fully inside a solid.
startsolid:booleanpropWhether the trace started inside a solid.
startpos:Vector3propStart position as a field.
endpos:Vector3propEnd position as a field.
Press HOME to test whether you have a clear ray to the nearest enemy, and who blocks it.
callbacks.Register("CreateMove", function()
if not input.IsButtonPressed(KEY_HOME) then return end
local me = client.GetLocalPlayer()
if not me:IsValid() then return end
-- nearest living enemy
local best, bestDist = nil, math.huge
for _, ent in pairs(entities.GetPlayers()) do
if ent:IsValid() and ent:IsAlive() and ent:GetTeam() ~= me:GetTeam() then
local d = vector.Distance(me:GetAbsOrigin(), ent:GetAbsOrigin())
if d < bestDist then best, bestDist = ent, d end
end
end
if not best then
print("no enemies")
return
end
-- ray from your eye to their chest
local tr = trace.Line(me:GetEyePosition(), best:GetAbsOrigin() + Vector3(0, 0, 64))
if tr.fraction >= 0.99 or (tr:DidHitEntity() and tr:GetEntity():GetIndex() == best:GetIndex()) then
print(string.format("clear LOS to %s", best:GetName()))
else
local blocker = tr:DidHitEntity() and tr:GetEntity():GetName() or "world"
print(string.format("blocked by %s at %.1f%%", blocker, tr.fraction * 100))
end
end)
Drops a ray straight down to find the floor below you, its height, and the surface normal.
local last = 0
callbacks.Register("CreateMove", function()
local tick = globals.TickCount()
if tick - last < 66 then return end
last = tick
local me = client.GetLocalPlayer()
if not me:IsValid() then return end
local tr = trace.Line(me:GetEyePosition(), me:GetEyePosition() - Vector3(0, 0, 2000))
if tr:DidHit() then
print(string.format("ground %.0f units below, normal (%.2f, %.2f, %.2f)",
me:GetEyePosition().z - tr:GetEndPos().z, tr.plane.x, tr.plane.y, tr.plane.z))
else
print("nothing below")
end
end)