For the longest time I have been checking if a part exist at a specific point like this
local function checkCollisionAtPoint(pos, pointRadius)
return #workspace.Obstacles:GetPartBoundsInRadius(pos, pointRadius, OVERLAP_PARAMS) > 0
end
Which worked fine for the retro slop look the game had because it only get the bounding box but now I want to go out of retro slop to have actually good model now and it is causing problem because these mesh bounding box are not the bounding box shape.
And as far as I know there isn’t a easy way to check this optimally (I run the previous function like 4000 time a frame)
I tried Spherecast and it just return nil tried to find why but didnt find a way.
I tried GetPartsInPart but it cause insane lag because I need to create a part for every moving entity and check for their future position and it just doesnt work even with pooling.
So I’m asking does anyone know how to check if a Basepart exist at specific point?
1 Like
Try GetPartsInPart. It’s also a spatial query so it should be optimized well enough for a majority of use cases.
I missed the section where you said you already tried GetPartsInPart, apologies for the oversight. However if that didn’t work, there isn’t much else you can do to have both accurate and optimized mesh collision checks, GetPartsInPart is already as optimized as it can get. Anything you implement yourself will simply be inferior because of the Luau/C++ boundary.
Though have you tried reusing the “selector” part & constraining the query by excluding/including certain instance hierarchies?
Didnt solve the issue but made me realised something
local Obstacles: WorldModel = workspace.Obstacles
local OVERLAP_PARAMS = OverlapParams.new()
OVERLAP_PARAMS.MaxParts = 1
local _checkPart = Instance.new("Part")
_checkPart.Anchored = true
_checkPart.CanCollide = false
local function checkBasicCollisionAtPoint(pos, pointRadius)
return #Obstacles:GetPartBoundsInRadius(pos, pointRadius, OVERLAP_PARAMS)
end
local function checkCollisionAtPoint(pos, pointRadius)
_checkPart.Position = pos
_checkPart.Size = Vector3.new(pointRadius, pointRadius, pointRadius)
return #Obstacles:GetPartsInPart(_checkPart, OVERLAP_PARAMS) > 0
end
For some reason my brain for the past long years I though every entity had to have a position part but not there could just be one that is moved around when check is needed and i could just split the the logic into basic collision and if there were no collision i could just ignore and if it did hit I could then use more expensive solution because most entities aren’t hugging the wall in the corner or something
Here’s the solution badge for helping me get the new mental model 
1 Like