GetTouchingParts() is too laggy, but I can't find an alternative

Hello, this is my first Topic so please be sure to tell me if I’m doing something wrong.

I’m trying to create a mirror module script for houses. I have most of it down, and I’m almost done, but I have an issue. You see, I’m trying to make it so if players pass through the area where a player might be looking through, I want them to go invisible, so they can’t disrupt the reflection. The problem is that I want the regions that check if the player is inside them to be able to be rotated, and what I have been using, Region3 can’t do rotations, so I had to result to GetTouchingParts (Which is much more expensive). Because this runs every RunService Heartbeat, the game lags a lot when trying to find who is inside.

Aside from that, here’s the main question.

Is there a way to check for player’s in a rotated region (by the way, the region is based on a part)

Here is a diagram


How do I rotate this red region. Region3 doesn’t allow rotation, and GetTouchingParts() is too laggy, so how do I do this

Might work for you.

Hm, I’ll look into this, thanks for your help.

Or, way more simply, if the part’s a rectangle and you can simplify the question to “is the position of a player inside this part”:

local function IsPointInsidePart(point, part)
    local relative = part.CFrame:PointToObjectSpace(point)
    local halfSize = part.Size / 2
    return relative.X >= -halfSize.X and relative.X <= halfSize.X
	    and relative.Y >= -halfSize.Y and relative.Y <= halfSize.Y
	    and relative.Z >= -halfSize.Z and relative.Z <= halfSize.Z
end
1 Like

Ah, this seems to be very interesting. It seems like it would save my performance in a swing. I’ll test it out and get back when I’m done.

Thank you so much, worked flawlessly, with no destructive impact on the performance.

2 Likes

A very easy way I have learned is that if you toggle collision on and off .Touched will fire. As you flick it on and off so quick it means that it wont effect anything it touches either.