Part on Part universal encapsulation checking

Have you ever needed to check if a Part is entirely inside of another Part, not just touching it? This is a function that does just that!

PartEncapulatesPart(boundPart, containedPart) will return true if containedPart is entirely within boundPart, otherwise it returns false.

It supports any Part shape against any other Part shape.

You can find it here: PartEncapsulatesPart - Creator Store

If this functionality isn’t enough, the function also supports a third parameter! This is a string, either “X”, “Y”, or “Z”, and it dictates the local axis about which you are trying to check the boundary.

It essentially lets you do an infinite bound check along that local axis, with proper bounds. See these video for a better explanation:

Cylinder about “X” axis (will “cast” the circle shape infinitely along its local x-axis):

Wedge about “X” axis:

Corner wedge about “X” axis:

I hope this helps someone! Note that nothing needs to be axis aligned, everything works with rotations.

FAQ

Q: Is it performant?

A: Yes, but you should still take care to use it in moderation. Look at this gif, this is 96 various parts being checked against a cylinder every frame:
PerformanceShowcase

Q: Is it parallel-safe?

A Yes. It just uses math under the hood, so everything can be done with Actors.

10 Likes