Yo this is a tutorial on what a region3 is and how u can use it.
Region3 is a data type that describes a volume in 3D space similar to an axis-aligned rectangular prism. simply put its like a part that only has a CFrame and Size Property. an example of a region3 is the terrain cells that terrain editor uses.
Region3 is commonly used as a replacement of hitbox parts.
it can be created using Region3.new()
so its parameters are -
- the position of the top left front of a part
2.the position of the top right back of a part
so the simplest way to calculate these Vector3 s and use them to make a Region3 is -
local part = Instance.new("Part")
part.Parent = game.Workspace
local TopLeftFrontOfPart = part.Position + Vector3.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)
local TopRightBackOfPart = part.Position + (Vector3.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)*-1)
local region = Region3.new(TopLeftFrontOfPart,TopRightBackOfPart)
now this region has 2 properties -
-
region.CFrame
which is the CFrame of the region3 -
region.Size
is a Vector3 of the Size of the part
so if u want to check what parts are touching a region3 there are 3 ways-
-
local partsTouchingRegion = game.Workspace:FindPartsInRegion3()
this returns a table with all the parts that are touching the region3, its parameters are the region,aPartToBeIgnored, maxParts (maximum no. of parts that can be returned) -
local partsTouchingRegion = game.Workspace:FindPartsInRegion3WithIgnoreList()
this returns a table of all parts touching the region3 except the ones in the ignore list. its params are the region, a tableWiththePartsToIgnore , maxParts
3.local partsTouchingRegion = game.Workspace:FindPartsInRegion3WithWhiteList()
this returns a table of parts that are in the region3 and in the whitelist. its params are the region, tableWithPartsToNotIgnore, maxParts
you can use different methods based on your requirements but for this tutorial I am going to be using the 1st one since its the simplest
local part = Instance.new("Part") --creates part
part.Parent = game.Workspace --setsParent
part.Name = "Chidori go brrrrrr" -- sets name of parent u *dont* need to do this I did it for fun
part.Size = Vector3.new(15,15,15)
local TopLeftFrontOfPart = part.Position + Vector3.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2) --calculates 1st parameter for region3
local TopRightBackOfPart = part.Position +(Vector3.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)*-1) -- calculates 2nd parameter for region3
part.Size = Vector3.new(5,5,5)
local region = Region3.new(TopLeftFrontOfPart,TopRightBackOfPart) --creates region3
local getTouchingParts = game.Workspace:FindPartsInRegion3() -- gets table of all parts in region3
for i,v in pairs(getTouchingParts) do --loops through the table
print(v.Name) -- prints name of the part in the loop right now
end -- ends the loop why am I even writing so many obvious things...
so the above code creates a part then creates a region 3 with the the same position and size as the part (and later makes the part smaller just like that) after this it gets a table of all the parts in the region 3 and then loops through it to print the name of all parts in the region3
hmu on discord (Ichigo#5972) for requesting more tutorials