So I have a placing system, and I only want the player to place some model only inside of an area, so when the player want to place a model, they will send a remote with the model and a frame so the player can process, so how do I find if that Cframe is in the Region, without creating a part.
1 Like
I wrote this function that will likely solve your issue
function isVector3inRegion3(region,vector)
rSize = region.Size
rVector = region.CFrame.p
xVector = vector.X
xrSize = rSize.X
xrVector = rVector.X
x1 = xrVector + (math.abs(xrSize/2))
x2 = xrVector - (math.abs(xrSize/2))
if xVector > math.max(x1,x2) or xVector < math.min(x1,x2) then
return false
end
yVector = vector.Y
yrSize = rSize.Y
yrVector = rVector.Y
y1 = yrVector + (math.abs(yrSize/2))
y2 = yrVector - (math.abs(yrSize/2))
if yVector > math.max(y1,y2) or yVector < math.min(y1,y2) then
return false
end
zVector = vector.Z
zrSize = rSize.Z
zrVector = rVector.Z
z1 = yrVector + (math.abs(zrSize/2))
z2 = yrVector - (math.abs(zrSize/2))
if zVector > math.max(z1,z2) or zVector < math.min(z1,z2) then
return false
end
return true
end
Haven’t had the time to test it, so let me know if it works for tou.
1 Like
I already found a solution, but thank you for your contribution
local function isInRegion3(region, point)
local relative = (point - region.CFrame.p) / region.Size
return -0.5 <= relative.X and relative.X <= 0.5
and -0.5 <= relative.Y and relative.Y <= 0.5
and -0.5 <= relative.Z and relative.Z <= 0.5
end