GetTouchingParts(), but it also gets adjacent parts?

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.

If someone has any idea, that would help me a lot :slight_smile:


Could you provide your use case or why you need such function?

I added the part about explanation.

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.

With the proper implementation, this should work just fine.

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 +, n, n)
      clone.Name = "clone"
      clone.CFrame = part.CFrame
      if (clone:IsA("WedgePart")) then
          clone.Size = clone.Size +, n, n)
          clone.CFrame = part.CFrame *, n / 2, -n /2)
      if (clone:IsA("CornerWedgePart")) then
          clone.Size = clone.Size +, n, n)
          clone.CFrame = part.CFrame * / 2, n / 2, n / 2)
      return clone
  local hitbox = createLargerHitbox(part)
  local touchingParts = hitbox:getTouchingParts()

  return touchingParts

The CFrame part sounded tricky - but thankfully you had an idea.
I can modify it a little to have cached hitbox parts.

MeshParts won’t be an issue for now, I think.

1 Like