However, the problem is that this works only if it’s in contact of parts either to the side or on top, but it doesn’t detect anything under itself.
Video demonstration:
‘Part’ is a basepart that detects the GetPartsInPart, this video demonstrates that regardless of collision or anchored, it neglects the bottom side of itself.
Any help would be great, thanks.
Note: I’m using more complex shapes later on, so using GetPartBoundsInBox wouldn’t be of help in those scenarios.
Maybe you could use Region3 to find the parts close to / in the part. Something like this maybe:
while task.wait() do
local partPosition = script.Parent.Position
local partSize = script.Parent.Size
local region = Region3.new(partPosition - partSize/2, partPosition + partSize/2)
local partsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge)
for _, part in pairs(partsInRegion) do
-- Code
end
end
GetPartsInPart, as the name of the method suggests, will only get parts that are inside of the specified part. Naturally a part that is only touching it but not actually inside of it will not count so it’s working as intended.
You should attach a slightly larger invisible non-collide part to it and use that as the hitbox for your check instead to also get “touching” parts.
As shown in the video, the white block (detecting) is very well near the center of mass of the grey part but the output still prints out {}, aka nothing.
It was also demonstrated that the detecting part does not need something to be inside because it detects the touch of a wall when both parts are collidable and the detector is not anchored, aka physics does its thing and pushes them both outside of their volumes.
Try using BasePart:GetTouchingParts() if you want to detect parts that are both either touching (just on surfaces) or intersecting. WorldRoot:GetPartsInPart() attempts to only query parts that are intersecting the part you are checking against. There is going to be some overlap against some surfaces due to float point errors.
A more comprehensive solution (for non regular shaped parts) might be raycasting or shapecasting from all faces using a very short ray to detect whether or not parts are touching.
I’ve tried using GetTouchingParts() with a non colliding wall and it only detects the block under itself but not the wall regardless of position or intersections. However I’m thinking about combining both techniques GetTouchingParts() and GetPartsInPart() to make it more accurate. Thanks.
According to the Roblox Creator Hub, a non collidable part must have a TouchInterest, which can only be done if I insert a function .Touched into the desired non collidable part.
This then makes it eligible to be detected by the separate GetTouchingParts(), detectable if it is either touching by surface or its volume inside the detecting part.
Note: Either one of the interacting parts needs a TouchInterest, ex: Character limbs do not need TouchInterest if the Part already has one like in the video.