Check if point is within a bounding region

Hey! For various tasks, I need to check if a point is contained within a rectangular region (defined by two points)

function IsInRegion(Pos,A,B)
return (Pos.X < math.max(A.X,B.X) and Pos.X > math.min(A.X,B.X)) and (Pos.Y < math.max(A.Y,B.Y) and Pos.Y > math.min(A.Y,B.Y)) and (Pos.Z < math.max(A.Z,B.Z) and Pos.Z > math.min(A.Z,B.Z))
end

Here is my code - but unfortunately, it seems to have some sort of logical flaw which I’m unable to mitigate. Is there any pre-built system that might work, or in-engine solution?

So far I’ve tried:

  • AxisAngle’s Rotatable Region3 Module (broke really painfully and had a strange API that wasn’t suitable)
  • Region3s (these don’t work as I don’t need to check if a part is in the region, but if a Vector point is)

Thanks! :slight_smile:

5 Likes

Do you know what the logical flaw is or what problems you are facing when using this? I quickly tested the function and it returns true when a given Vector3 position is within positions A and B.

Figured out the issue!

It was another part of my logic which was providing false limits. Sorry for the silly post :stuck_out_tongue:

The Box code works great, for anyone who wants to use it :slight_smile:

2 Likes