Skip to content

OverlapParams ​

可以限定参与检测的单位范围、碰撞组以及返回结果的最大数量。配合包围盒、半径与单位相交三类查询使用,它决定哪些单位会进入结果集。

概览 ​

可以限定参与检测的单位范围、碰撞组以及返回结果的最大数量。配合包围盒、半径与单位相交三类查询使用,它决定哪些单位会进入结果集。

可通过 OverlapParams.New() 构造

代码示例 ​

创建 OverlapParams 并传入空间查询

lua
-- @runtime client
local PhysicsService = game:GetService('PhysicsService')
local World = game:GetService('World')
local targetUnit = World:CreateUnit('WorldUnit', { Position = Vector3.New(0, 0, 0) })
local params = OverlapParams.New()
params.FilterType = Enums.RaycastFilterType.Include
params.FilterDescendantsInstances = { targetUnit }
params.MaxParts = 10
local units = PhysicsService:GetPartBoundsInRadius(Vector3.New(0, 0, 0), 20, params)
print('命中数量:', #units)
targetUnit:Destroy()

属性 ​

名称类型默认值说明
FilterTypeInt0过滤模式:Exclude 排除列表中的实例,Include 仅检测列表中的实例。
FilterDescendantsInstancesArray[]空间查询参数中用于承载被过滤 Unit 的数组属性,存储一组 Unit,配合过滤类型决定这些 Unit 是被排除在查询结果之外,还是仅保留这些 Unit。
CollisionGroupString-用于按已配置碰撞关系过滤的碰撞组名称,不是只按 WorldUnit.CollisionGroup 字符串同名匹配;不设置(nil,Meta 默认值)表示不启用碰撞组过滤。
MaxPartsInt0限制区域查询返回的最大实例数量。