So supposedly, Region3
can take place in a form of a specific region you want to capture inside the workspace
itself
For the example that was shown, I believe it takes 2 Vector3
values & converts it into a Region (Or a square radius for more simplistic terms), and you can get the center of where that Region is exactly (Keep in mind though, that your Region3
example is relative to the world origin)
The most common use for Region3
is detecting if something is in a specific Region, which can be useful for checking square boundaries (Of course we have Magnitude as well, but that’s implemented as a radius implemented as a circle)
Say we wanted to detect if a object was in a specific Region, well we’d first need to get our Sizes so we can compare what the medium between the 2 can be:
local RegionPart = workspace.Part
local MinSize = RegionPart.Position - (0.5 * RegionPart.Size)
local MaxSize = RegionPart.Position + (0.5 * RegionPart.Size)
local Region = Region3.new(MinSize, MaxSize)
Creating a Region3
requires a “MinSize”, and “MaxSize” then I believe it divides & takes the medium of both those Sizes
After we have our Region we created, we can then put it through a while true do
loop so that it’ll check frequently for nearby parts/objects:
while true do
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, nil)
wait(1)
end
FindPartsInRegion3
would return back an Array (Or table which would be this: {}), and it has 3 parameters:
-
The Region we just created
-
The part (And it’s descendants) that we want to ignore when we check for the Region
-
A max counter for the amount of parts we want to detect in that Region (Setting it to nil
would be infinite I believe)
After we have our Parts, we can loop through our table & check if a Random Object is inside the Region at all:
--Inside our loop
for _, Part in pairs(Parts) do
if Part.Name == "GreenPart" then
print("This Green Part is inside the Region!")
end
end
Of course, if we’d wanna get a Player we can check using the GetPlayerFromCharacter
function & referencing the Part’s Parent
But yeah that’s the basis of that Region3
can do! Kinda think of it as like taking a chunk of the world & detecting that “chunk” for parts that could be inside
local RegionPart = workspace.Part
local MinSize = RegionPart.Position - (0.5 * RegionPart.Size)
local MaxSize = RegionPart.Position + (0.5 * RegionPart.Size)
local Region = Region3.new(MinSize, MaxSize)
while true do
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, nil)
for _, Part in pairs(Parts) do
if Part.Name == "GreenPart" then
print("This Green Part is inside the Region!")
end
end
wait(1)
end