Is it possible to check if a face of a part is overlapping with another face?

Hello developers, I’d like to know if it’s possible to check if a specific face of a part is overlapping with another face.

Any help with this would be greatly appreciated.
Thanks, MBroNetwork.

1 Like

Theres a lot of ways a face can be overlapping, what do you mean specifically?

1 Like

I want to see if the front face is overlapping with another face of another part in-front of it.

Yeah but do you mean like this:


Or touching like this?:

Or even if one parts face intersects the other’s face when projected onto it?

1 Like

Oh, sorry, I was kind of confused, I mean if the faces touch.

Do you want to know if the faces touch or intersect at all? like even if they are at an angle to each other, or only if they are flat with each other (flush)? One is much easier

1 Like

Its highly likely you can avoid any math if you can make your application work using this: BasePart | Roblox Creator Documentation

1 Like

GetConnectedParts only works with assemblies (of unanchored and rigidly connected parts). GetTouchingParts might work in a pinch.

To compute whether two bricks’ faces touch, you must first check:

  • whether the faces’ normals are parallel, but facing opposite each other - if you’re checking only the front faces, then do partA.CFrame.LookVector:FuzzyEq(-partB.CFrame.LookVector).
    There’s also the :Dot() thing for checking the angle between two 3D directions.
  • whether the parts are at exactly the right distance - if you’ve already verified that the faces are aligned and you’re dealing with both Front faces, do math.abs(partA.CFrame:PointToObjectSpace(partB.Position).Z - (partA.Position.Z + partB.Position.Z) / 2) < 0.0001.
    PointToObjectSpace will get their relative position accounting for A’s rotation, .Z is distance of partB’s center from partA’s XY plane, the stuff with the positions is half A’s thickness behind its front face + half B’s thickness behind its front face, the 0.0001 is just a small enough epsilon.

Substitute stuff with XVector, YVector, negatives of these, different components of sizes etc. as needed.

1 Like

I would like to know if they’re flat with each other.

The problem is that I’m checking any face that the front face is flat with.
Edit: *flat with and vice versa.

Then repeat with all faces. It’s as simple as that.

Or only half of them, since if the front face is facing the same way (instead of the opposite way) as the face you’re testing against and the distance is right, then that means the back face is in contact instead - check whether direction:Dot(direction) is close to zero to figure this out.

1 Like

Would getting the touching parts and then taking the coordinates of each part and comparing with the original work as an alternative way to detect this? (ex. Part on the left is touching the original part, if part is found to be to the left of the original part then the left side of the original part is touching something)

The best way to find out is to just try it and see.

GetTouchingParts by itself isn’t too good here because a touching part can be oriented in any way. It might be touching the other part’s face with just a corner or an edge, so you might still be forced to check whether XVector, YVector or ZVector :Dot(normal of the original's face) is approximately 0, i.e. one of the faces is oriented the same way as the face you’re checking.

But nevermind, if the part is at exactly the right distance, then it doesn’t matter because it’s reasonably likely to be flat against the face anyway.


(Drew this because I wanted to draw something)

Yeah GetTouchingParts is a better option than I thought because it saves you from manually checking parts that might not even be near the original part. Get touching parts and then do something like

local normal = original.CFrame.LookVector -- the direction that the front face of the 'original' part (as you call it) is facing
local cf = part.CFrame
-- check whether any of the target part's axes are facing approximately the same direction
return math.abs(cf.XVector:Dot(normal)) < 0.01 or math.abs(cf.YVector:Dot(normal)) < 0.01 or math.abs(cf.ZVector:Dot(normal)) < 0.01

This doesn’t tell you which face of the part is on the original part, just that one of them is.

If GetTouchingParts is returning nothing and your part is anchored or rigidly attached to an anchored part, then add a Touched event to the original part. The listener can be function() end, it just needs to be there. Maybe this bug has already been fixed, I don’t know.

OK I’m done rambling

2 Likes