跳至正文
版本:最新版 - a1.169.2 ⚖️

🔍 Trace

追踪一条射线穿过世界,获取碰撞物体的信息。

🗿Static ClassClient Only🧑‍💻API Source

🎒 示例​

Client/Index.lua
-- 获取本地玩家
local local_player = Client.GetLocalPlayer()

-- 获取相机的旋转和位置
local camera_rotation = local_player:GetCameraRotation()
local start_location = local_player:GetCameraLocation()

-- 根据相机旋转计算方向向量
local direction = camera_rotation:GetForwardVector()

-- 计算追踪的结束位置
-- (起始位置 + 相机方向上的 20000 个单位)
local end_location = start_location + direction * 20000

-- 过滤我们想要追踪的所有内容(例如 WorldStatic、WorldDynamic、PhysicsBody、Vehicle)
local collision_trace = CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle

-- 定义追踪的参数
-- TraceMode.TraceOnlyVisibility 表示我们只检测可见的对象
-- TraceMode.DrawDebug 表示我们要绘制调试线以实现可视化
-- TraceMode.TraceComplex 表示我们要针对复杂碰撞形状进行追踪
-- TraceMode.ReturnEntity 表示我们要返回被追踪命中的实体
local trace_mode = TraceMode.TraceOnlyVisibility | TraceMode.DrawDebug | TraceMode.TraceComplex | TraceMode.ReturnEntity

-- 执行追踪
local trace_result = Trace.LineSingle(start_location, end_location, collision_trace, trace_mode)

-- 如果追踪成功
if (trace_result.Success) then
-- 如果获取到了实体,打印发生碰撞的实体名称,否则仅打印位置
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
-- 如果追踪未成功,打印提示消息
Console.Log("Failed to trace")
end

🗿 静态函数​

ReturnsNameDescription
table of tableBoxMulti使用物体类型对世界进行框体追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞
tableBoxSingle对世界进行框体追踪,并返回一个包含第一个阻挡碰撞信息的表
table of tableCapsuleMulti使用物体类型对世界进行胶囊体追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞
tableCapsuleSingle对世界进行胶囊体追踪,并返回一个包含第一个阻挡碰撞信息的表
table of tableLineMulti使用物体类型对世界进行射线追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞
tableLineSingle对世界进行射线追踪,并返回一个包含第一个阻挡碰撞信息的表
table of tableSphereMulti使用物体类型对世界进行球体追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞
tableSphereSingle对世界进行球体追踪,并返回一个包含第一个阻挡碰撞信息的表

Moderate

BoxMulti​

使用对象类型对世界进行盒体追踪,返回重叠命中和第一个阻挡命中。

注意:即使下面忽略了该通道,追踪仍会与对象类型(在碰撞设置中)发生碰撞。

结果已排序,因此阻挡命中(如果找到)将是数组的最后一个元素。

只会生成单个最近的阻挡结果,之后不会再进行任何检测。
local ret = Trace.BoxMulti(start_location, end_location, half_size, orientation, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 框体的起始位置
Vectorend_location Required parameter 框体的结束位置
Vectorhalf_size Required parameter 从框体中心沿每个轴的距离
Rotatororientation Required parameter 框体的朝向
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table of table包含每次命中详细信息的表的列表 with this format

Moderate

BoxSingle​

对世界进行框体追踪,并返回一个包含第一个阻挡碰撞信息的表。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。
local ret = Trace.BoxSingle(start_location, end_location, half_size, orientation, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 框体的起始位置
Vectorend_location Required parameter 框体的结束位置
Vectorhalf_size Required parameter 从框体中心沿每个轴的距离
Rotatororientation Required parameter 框体的朝向
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table包含命中信息的表 with this format

Moderate

CapsuleMulti​

使用物体类型对世界进行胶囊体追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。

结果已排序,因此阻挡碰撞(如果找到)将是数组的最后一个元素

只会生成单个最近的阻挡结果,之后不会再进行测试
local ret = Trace.CapsuleMulti(start_location, end_location, radius, half_height, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 胶囊体的起始位置
Vectorend_location Required parameter 胶囊体的结束位置
floatradius Required parameter 要扫描的胶囊体半径
floathalf_height Required parameter 从胶囊体中心到半球形端部顶点的距离。
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table of table包含每次命中详细信息的表的列表 with this format

Moderate

CapsuleSingle​

对世界进行胶囊体追踪,并返回一个包含第一个阻挡碰撞信息的表。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。
local ret = Trace.CapsuleSingle(start_location, end_location, radius, half_height, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 胶囊体的起始位置
Vectorend_location Required parameter 胶囊体的结束位置
floatradius Required parameter 要扫描的胶囊体半径
floathalf_height Required parameter 从胶囊体中心到半球形端部顶点的距离。
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table包含命中信息的表 with this format

Moderate

LineMulti​

使用物体类型对世界进行射线追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。

结果已排序,因此阻挡碰撞(如果找到)将是数组的最后一个元素

只会生成单个最近的阻挡结果,之后不会再进行测试
local ret = Trace.LineMulti(start_location, end_location, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 射线的起始位置
Vectorend_location Required parameter 射线的结束位置
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table of table包含每次命中详细信息的表的列表 with this format

Moderate

LineSingle​

对世界进行射线追踪,并返回一个包含第一个阻挡碰撞信息的表。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。
local ret = Trace.LineSingle(start_location, end_location, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 射线的起始位置
Vectorend_location Required parameter 射线的结束位置
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table包含命中信息的表 with this format

Moderate

SphereMulti​

使用物体类型对世界进行球体追踪,并返回重叠的碰撞,然后返回第一个阻挡的碰撞。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。

结果已排序,因此阻挡碰撞(如果找到)将是数组的最后一个元素

只会生成单个最近的阻挡结果,之后不会再进行测试
local ret = Trace.SphereMulti(start_location, end_location, radius, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 球体的起始位置
Vectorend_location Required parameter 球体的结束位置
floatradius Required parameter 球体的半径
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table of table包含每次命中详细信息的表的列表 with this format

Moderate

SphereSingle​

对世界进行球体追踪,并返回一个包含第一个阻挡碰撞信息的表。

注:即使下方忽略了该通道,追踪仍会与碰撞设置中的 ObjectType 发生碰撞。
local ret = Trace.SphereSingle(start_location, end_location, radius, collision_channel?, trace_mode?, ignored_actors?)

Parameters

TypeParameterDefaultDescription
Vectorstart_location Required parameter 球体的起始位置
Vectorend_location Required parameter 球体的结束位置
floatradius Required parameter 球体的半径
CollisionChannel or integercollision_channel?WorldStatic
支持多个通道,使用 | 分隔(使用按位运算)
TraceMode or integertrace_mode?0
追踪模式,传递所有参数并使用 | 分隔(使用按位运算)

你需要显式传递模式以返回你想要的值
table of Base Actorignored_actors?{}
在追踪过程中需要忽略的 Actor 数组

Returns

TypeDescription
table包含命中信息的表 with this format

🚀 事件​

This class doesn't have own events.