So I have a very large map and I’m trying to create a border for it. If the player leaves the border they are then met with a prompt which brings them back into the map.
My issue is that I’m using Region3 along with GetPartsInBoundBox to detect when a player enters and leaves inside/outside the borders.
Here is a rough demonstration of my code:
local pointA = workspace.Point1
local pointB = workspace.Point2
local region = Region3.new(pointA, pointB)
If I were to visualize this region by setting a part’s CFrame and Size to the regions CFrame and Size it looks inaccurate along with when I playtest it does not detect when a player enters/leaves the bounds.
For those looking for the answer: Orientation is taken into account with Region3s!
This is not a good option in comparison to Region3 where instead of performing the calculations in Luau (slower) you can just run it by using WorldRoot:FindPartsInRegion3()
Edit: This also works better because you can define definite points a bit easier
e.g:
local Region = Region3.new(Point1.Position, Point2.Position)
local Parts = workspace:FindPartsInRegion3(Region)
for _, Part in Parts do
print(Part.Name)
end
I’ve tried the exact same Region3 creation code you provided before I created this topic however it did not work unfortunately. It seems its not filling in the space how I want it as seen in this picture:
Then, in that case I’d suggest you just check the 3D Position is within bounds like
local Bounds = { A = Point1.Position, B = Point2.Position }
local function WithinBounds(Position: Vector3)
if (Position.X < math.max(Bounds.A.X, Bounds.B.X) and Position.X > math.min(Bounds.A.X, Bounds.B.X)) then
if (Position.Z < math.max(Bounds.A.Z, Bounds.B.Z) and Position.Z > math.max(Bounds.A.Z, Bounds.B.Z)) then
return true
end
end
return false
end
--> Just use this as a test or delete it, just an example.
if (WithinBounds(Vector3.new(10, 2, 15))) then
print("In bounds!")
end
Although I’m unaware why Region3 isn’t working for you. I’ll try to look into this.
Edit: Made it work without “Min” and “Max” values.
Well, Region3 is naturally faster but if Region3 isn’t working well I’d suggest using Region3int16 because it’s easier to work with bounds and you can just convert it to Region3 to see the results. Keep in mind this does not have inbuilt things like WorldRoot:FindPartsInRegion3(), but it can be easier to work with if you’re using a point-defined Region3 system.
If you don’t want to be insanely specific you can also use distance magnitudes to check the distance from the centre point!
I may just try to check if the 3D Position is in bounds like you said, When I print the region though it returns a Size of {-8771.099609375, -1983.1002197265625, 16374.7998046875}
It also returns a CFrame of {-1219.19971, 1045.90015, 6331.8999, 1, 0, 0, 0, 1, 0, 0, 0, 1}
For anyone who comes across this topic and is wondering how I solved it:
What I did not realise when creating the region is that it takes into account the Orientation of the parts, as soon as I flipped the orientation it began working.