Ir para o conteúdo principal
Version: latest - a1.172.0 ⚖️

🔍 Trace

Trace a ray against the world and get collided objects information

🗿Static ClassClient Only🧑‍💻API Source

🎒 Examples​

Client/Index.lua
-- Gets the local player
local local_player = Client.GetLocalPlayer()

-- Gets the camera rotation and location
local camera_rotation = local_player:GetCameraRotation()
local start_location = local_player:GetCameraLocation()

-- Calculates the direction vector based on the camera rotation
local direction = camera_rotation:GetForwardVector()

-- Calculates the end location of the trace
-- (start location + 20000 units in the direction of the camera)
local end_location = start_location + direction * 20000

-- Filter everything we want to trace (e.g. WorldStatic, WorldDynamic, PhysicsBody, Vehicle)
local collision_trace = CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle

-- Define the parameters for the trace
-- TraceMode.TraceOnlyVisibility means we only want to trace against objects that are visible
-- TraceMode.DrawDebug means we want to draw debug lines for the trace for visualization
-- TraceMode.TraceComplex means we want to trace against complex collision shapes
-- TraceMode.ReturnEntity means we want to return the entity that was hit by the trace
local trace_mode = TraceMode.TraceOnlyVisibility | TraceMode.DrawDebug | TraceMode.TraceComplex | TraceMode.ReturnEntity

-- Do the trace
local trace_result = Trace.LineSingle(start_location, end_location, collision_trace, trace_mode)

-- If the trace was successful
if (trace_result.Success) then
-- And we got an entity, print the name of the collided entity, otherwise just print the location
if (trace_result.Entity) then
Console.Log("Trace Success! Entity: " .. tostring(trace_result.Entity) .. ". Location: " .. tostring(trace_result.Location))
else
Console.Log("Trace Success! Location: " .. tostring(trace_result.Location))
end
else
-- If the trace was not successful, print a message
Console.Log("Failed to trace")
end

🗿 Static Functions​

BoxMulti: table of tableTrace a box against the world using object types and return overlapping hits and then first blocking hit
BoxSingle: tableTrace a box against the world and returns a table with the first blocking hit information
CapsuleMulti: table of tableTrace a capsule against the world using object types and return overlapping hits and then first blocking hit
CapsuleSingle: tableTrace a capsule against the world and returns a table with the first blocking hit information
LineMulti: table of tableTrace a ray against the world using object types and return overlapping hits and then first blocking hit
LineSingle: tableTrace a ray against the world and returns a table with the first blocking hit information
SphereMulti: table of tableTrace a sphere against the world using object types and return overlapping hits and then first blocking hit
SphereSingle: tableTrace a sphere against the world and returns a table with the first blocking hit information

BoxMultiModerate​

Trace a box against the world using object types and return overlapping hits and then first blocking hit

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below.

Results are sorted, so a blocking hit (if found) will be the last element of the array

Only the single closest blocking result will be generated, no tests will be done after that

local ret = Trace.BoxMulti(start_location, end_location, half_size, orientation, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the box
end_locationVectorEnd location of the box
half_sizeVectorDistance from the center of box along each axis
orientationRotatorOrientation of the box
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
table of tableList of tables with the hit information of each hit
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

BoxSingleModerate​

Trace a box against the world and returns a table with the first blocking hit information

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below

local ret = Trace.BoxSingle(start_location, end_location, half_size, orientation, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the box
end_locationVectorEnd location of the box
half_sizeVectorDistance from the center of box along each axis
orientationRotatorOrientation of the box
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
tableTable with the hit information
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

CapsuleMultiModerate​

Trace a capsule against the world using object types and return overlapping hits and then first blocking hit

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below.

Results are sorted, so a blocking hit (if found) will be the last element of the array

Only the single closest blocking result will be generated, no tests will be done after that

local ret = Trace.CapsuleMulti(start_location, end_location, radius, half_height, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the capsule
end_locationVectorEnd location of the capsule
radiusfloatRadius of the capsule to sweep
half_heightfloatDistance from center of capsule to tip of hemisphere endcap
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
table of tableList of tables with the hit information of each hit
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

CapsuleSingleModerate​

Trace a capsule against the world and returns a table with the first blocking hit information

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below

local ret = Trace.CapsuleSingle(start_location, end_location, radius, half_height, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the capsule
end_locationVectorEnd location of the capsule
radiusfloatRadius of the capsule to sweep
half_heightfloatDistance from center of capsule to tip of hemisphere endcap
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
tableTable with the hit information
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

LineMultiModerate​

Trace a ray against the world using object types and return overlapping hits and then first blocking hit

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below.

Results are sorted, so a blocking hit (if found) will be the last element of the array

Only the single closest blocking result will be generated, no tests will be done after that

local ret = Trace.LineMulti(start_location, end_location, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the ray
end_locationVectorEnd location of the ray
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
table of tableList of tables with the hit information of each hit
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

LineSingleModerate​

Trace a ray against the world and returns a table with the first blocking hit information

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below

local ret = Trace.LineSingle(start_location, end_location, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the ray
end_locationVectorEnd location of the ray
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
tableTable with the hit information
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

SphereMultiModerate​

Trace a sphere against the world using object types and return overlapping hits and then first blocking hit

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below.

Results are sorted, so a blocking hit (if found) will be the last element of the array

Only the single closest blocking result will be generated, no tests will be done after that

local ret = Trace.SphereMulti(start_location, end_location, radius, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the sphere
end_locationVectorEnd location of the sphere
radiusfloatRadius of the sphere
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
table of tableList of tables with the hit information of each hit
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

SphereSingleModerate​

Trace a sphere against the world and returns a table with the first blocking hit information

Note: The Trace will collide with the ObjectType (in the Collision Settings), even if the channel is ignored below

local ret = Trace.SphereSingle(start_location, end_location, radius, collision_channel?, trace_mode?, ignored_actors?)
Parameters
NameTypeDescrição
start_locationVectorStart location of the sphere
end_locationVectorEnd location of the sphere
radiusfloatRadius of the sphere
collision_channel?CollisionChannel or integerSupports several channels separating by | (using bit-wise operations) Default WorldStatic
trace_mode?TraceMode or integerTrace Mode, pass all parameters separating by | (using bit-wise operations)

You need to explicitly pass the modes to return the values you want
Default 0
ignored_actors?table of Base ActorArray of actors to ignore during the trace Default {}
Returns
TypeDescrição
tableTable with the hit information
Table keys
NameTypeDescrição
SuccessbooleanNo description provided
LocationVectorNo description provided
ImpactPointVectorNo description provided
NormalVectorNo description provided
EntityBase ActorNo description provided
BoneNamestringNo description provided
ActorNamestringNo description provided
ComponentNamestringNo description provided
SurfaceTypeSurfaceTypeNo description provided
UVVector2DNo description provided
ItemintegerNo description provided

🚀 Events​

This class doesn't have own events.