How to ge the region3 in which an object is located?

I know you can check a certain region3 to see if there’s a certain object inside. But if I have several regions and the object could be in any of them, do I have to check every single region until I find it? Is there not a way to see which region3 the object is touching if it is overall touching any region?

1 Like

Are you creating the part that you are checking? If so you could check once on creation and store a variable that points to the Region3 it sits in.

Are the Region3 likely to overlap one another? i.e. could two Region3’s return true that the part is inside it?

Is there enough space between Region3’s that you could simplify the checking?

1 Like

Give this a try. For a single part, it should be more efficient than getting all parts in a region.

local function pointInRegion(point, region)
    local translated = region.CFrame:PointToObjectSpace(point)
    local size = region.Size * 0.5
    return translated.X > -size.X and translated.X < size.X
       and translated.Y > -size.Y and translated.Y < size.Y
       and translated.Z > -size.Z and translated.Z < size.Z
end
2 Likes

Thank you for your answers @dduck5tar and @JarodOfOrbiter. I decided to use completely different method for my purpose, which was a good idea. The part that I wanted to check was character’s root part, I should have mentioned that, my bad!