Hi. I need some suggestions on how to detect the bricks that are having a contact with eachother.
Let’s say parts are anchored, so I can’t use Touched. They don’t move at all. GetTouchingParts sadly only detects parts that are inside of the “hitbox”. I want more than that.
The reason why I need this function is basically applying status to bricks that are touching the source bricks. Can’t say much, project is secret for now.
“Why haven’t you tried making temporary parts with +.001 size?”
You see, parts like wedges won’t suffice. It could work with boxes, cylinders and spheres.
“Raycasting?”
Well, It could be okay - but I think it could only be good for spheres. Want to know why?
“Maybe GetConnectedParts while all the parts have welded surfaces? Don’t forget about MakeJoints.”
Good idea, but I’m worried a little. Would it affect perfomance when parts are anchored?
Plastic material will always show the texture.
Roblox Studio itself is able to detect the touching parts.
Move parts around with any Join setting that’s not “Never”.
I’m looking at their Built-in plugins in the hope of finding something.
My best guess for getting surrounding/adjacent parts is to use a Region3. Do note that Region3s can be performance heavy and have limitations such as not being able to be rotated(unless you use the Rotated Region3 module).
Yes, I have heard of Region3 but I really haven’t used it in past.
Would it work with CornerWedges, WedgeParts and anything else that has a non-box shape?
If I there was multiple parts, let’s say 30. Would it be really bad?
I worry about perfomance when multiple parts are affected. I don’t apply anything visual, so that’s kind of good.
Region3s are either square or rectangular and yes, they work on Corner Wedges and Wedge Parts, however you’d have to do additional checks to make sure that the part is actually adjacent with these “non-box” shaped parts.
So far, I’ve only experienced issues with huge Region3s, not multiple ones, so I guess having 30 shouldn’t be an issue. Do you need to check if a part is adjacent at the same time for all the parts? Or can you loop through each part and apply a function instead?
Well, I’m thinking about checking each brick which is about to apply the effect to nearby (adjacent / touching) bricks.
I will use CollectionService to check each “status giver” brick.
Changes to bricks will be applied to all the (whitelisted) bricks that were touching the “status giver” bricks.
Here’s a solution based on the “temporary parts with +.001 size” approach. It should work just fine if you don’t need absolute precision.
local function getAdjacentParts(part)
local function createLargerHitbox(part)
-- hitbox increase in studs
local n = 0.1
local clone = part:Clone()
clone.Parent = part.Parent
clone.Transparency = 0.8
clone.BrickColor = BrickColor.Red()
clone.Size = clone.Size + Vector3.new(n, n, n)
clone.Name = "clone"
clone.CFrame = part.CFrame
if (clone:IsA("WedgePart")) then
clone.Size = clone.Size + Vector3.new(0, n, n)
clone.CFrame = part.CFrame * CFrame.new(0, n / 2, -n /2)
end
if (clone:IsA("CornerWedgePart")) then
clone.Size = clone.Size + Vector3.new(n, n, n)
clone.CFrame = part.CFrame * CFrame.new(-n / 2, n / 2, n / 2)
end
return clone
end
local hitbox = createLargerHitbox(part)
local touchingParts = hitbox:getTouchingParts()
hitbox:Destroy()
return touchingParts
end