How would i get a area and check if a position is within that area?

Basically trying to find if a position is in a area, but without a part
Like i got the size and position of the area, just cant think on how i would find if a position is in or out of that area

Compare X, Y & Z values to that of the ones youâ€™d use to create a Region3.

how would i get the values to create the region3 though

Region3 supports arguments for minimum vector and maximum vector, these are the corners of your newly created Region3. Youâ€™d then compare the coordinates by checking if the X, Y & Z axis are within range between the two points.

well is there a method to getting corners of something?

You create the corners. Use Vector3.new

yeah but where im using the area is already a pre existing thing, is there still a viable method?

Create segments that correspond to your regionâ€™s corners, place them there, duplicate their locations, and insert them into the Vector3 values (or just use Part.Position). You may determine whether a point is within the range of two vectors by using the function Iâ€™ve built.

``````local minimumVector = Vector3.new(10, 10, 10)
local maximumVector = Vector3.new(-10, -10, -10)

local function checkInRange(point: Vector3, minimum: Vector3, maximum: Vector3): boolean
local x0, y0, z0 = point.X, point.Y, point.Z
local x1, y1, z1 = minimum.X, minimum.Y, minimum.Z
local x2, y2, z2 = maximum.X, maximum.Y, maximum.Z
return x0 < x2 and y0 < y2 and z0 < z2 and x0 > x1 and y0 > y1 and z0 > z1
end

checkInRange(Vector3.zero, minimumVector, maximumVector) --> true
checkInRange(Vector3.new(20, 0, 0), minimumVector, maximumVector) --> false
``````
1 Like

i get the region and corners thing, but im only making said area off of size and position and dont know if its possible to get corners from only 2 vectors, a size and a position (at the middle of the area)

Yes, use size & position to calculate the corner. You just add half the size to the position and an inverse of that half to another position variable. With that, youâ€™ll have both corners stored under a variable.

1 Like

Yep this worked
(Character limit)

How does this work, because, i tried but it donâ€™t work.

In the code, assume that `minimumVector` is situated at one corner, and the `maximumVector` is positioned at the entirely opposite side, which would be diametrically across from `minimumVector` to `maximumVector`.