I have created two bricks with the size of (0.05, 0.05, 0.05) at the top and bottom corners of a brick and I wanted to create a Region3 to check if the region is empty but for some reason it keeps saying that the region isEmpty when it should be printing false.
After trying to figure out what had been going wrong I checked the size of the Region and it was printing the Y and Z axis as negatives. I am assuming that this is the issue causing my problem but I cannot think of what’s causing this issue.
--Creating the Region3
function createRegion3(object)
local Point1 = object.Parent.Part0.Position
local Point2 = object.Parent.Part1.Position
local Region = Region3.new(Point1,Point2)
return Region
end
This is an example of one of the sizes which was printed, if I remove the minuses it becomes the correct size.
A region3 needs to be constructed with the first vector being the minimum and the second being the maximum. I believe you have to explicitly do this. You can do this using the min/max math functions:
--Creating the Region3
function createRegion3(object)
local Point1 = object.Parent.Part0.Position
local Point2 = object.Parent.Part1.Position
local Region = Region3.new(
Vector3.new(math.min(Point1.X, Point2.X), math.min(Point1.Y, Point2.Y), math.min(Point1.Z, Point2.Z)),
Vector3.new(math.max(Point1.X, Point2.X), math.max(Point1.Y, Point2.Y), math.max(Point1.Z, Point2.Z))
)
return Region
end
And to be fair, the documentation for Region3 does not explicitly state any of this. It seems very strange that a Region3 can have axis values in the negatives, since that is nonsensical in terms of what a ‘region’ is. You can tell that the implementation of this data type doesn’t do many checks-and-balances.