:GetPartBoundsInRadius() Not Respecting OverlapParams

Maybe I’m missing something obvious, but for context I’m using :GetPartBoundsInRadius() for enemy detection, as I have so many enemies that it’s more efficient to use SpatialQueries instead of iterating and calculating distance for each enemy. To try to make this more efficient, I set the collision group for each enemy’s root part to “Pet” and I set the target collision group to “Pet” as well, but it’s somehow printing printing parts not in the “Pet” collision group.

local RANGE = 50

function Pet:_CheckForEnemies()
	local Origin = self.PetRoot.Position
	
	local Enemies = game.Workspace:GetPartBoundsInRadius(Origin, RANGE, self._EnemyParams)
	warn(Enemies)
end



-- In another block of code:
self._EnemyParams = OverlapParams.new()
self._EnemyParams.CollisionGroup = "Pet"
self._EnemyParams.FilterType = Enum.RaycastFilterType.Exclude
self._EnemyParams.FilterDescendantsInstances = {self.FormationFolder}

_EnemyParams has CollisionGroup as “Pet”, so it would only query items which can collide with “Pet” collision group (check your collision groups window). You might have that “Pet” can’t collide with “Pet” but with “Default”, so that why it gives you everything except “Pet”. I usually make for this other collision group which i won’t use on parts or any other object on workspace, only for script queries. Make sure that new collision group will only collide with “Pet” and nothing more, so only “Pet” can be queried in GetPartBoundsInRadius.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.