A trace can be useful if you want to get the location of blocking things.
You will have to use a appropriate start position, often it can be your forward vector.
The fraction ranges from 0 to 1 and tells you at how many % the trace hit something.
For example if you trace from the origin (0, 0, 0) to (0, 0, 1000) and the fraction is 0.5, that means there is a blocking object at (0, 0, 500)
While the calculation is simple, we're providing a helper method
to obtain the hit location .
Properties
fraction
normal
surfaceFlags
contents
allSolid
startSolid
walkable
Methods
getHitLocation(start, end)
Returns the hit position of the trace.
Example:
local pointA = Vec3:new(0, 0, 0)
local pointB = Vec3:new(0, 0, 1000)
local trace = engine.trace(pointA, pointB)
local hitPosition = trace.getHitLocation()
if (trace.fraction < 1) then
print("Hit something at: " .. hitPosition:toString())
end