# Quick question. Can I use Region3 for a Sphere?

Instead of a Square fighting arena, I want to make a circle arena. so I can give the Players swords and alow fighting.

1 Like

Not really. But you could just do the math yourself. It sounds like you actually want a cylinder, not a sphere?

``````-- Checks if a given point is within the bounds of a vertical cylinder.
-- pos: Vector3 - the point to check
-- cylinderCenter: Vector3 - the center of the cylinder
-- cylinderHeight: number - the height of the cylinder
local function IsPositionInCylinder(pos, cylinderCenter, cylinderRadius, cylinderHeight)
local offset = pos - cylinderCenter;
local halfHeight = cylinderHeight / 2

-- pythagorean theorem without sqrt to get squared distance
local distanceSquared = offset.X * offset.X + offset.Z * offset.Z

return offset.Y > -halfHeight and offset.Y < halfHeight and distanceSquared < cylinderRadius * cylinderRadius
end
``````

You would just call that function, for example using the position of the playerâ€™s root part, and if it returns true you would give the player a tool or whatever.

If you really wanted a sphere instead...
``````-- Checks if a given point is within the bounds of a sphere.
-- pos: Vector3 - the point to check
-- sphereCenter: Vector3 - the center of the sphere
local offset = pos - sphereCenter;

local distanceSquared = offset.X * offset.X + offset.Y * offset.Y + offset.Z * offset.Z

end
``````

Edit: since I wrote this answer two years ago, roblox has highly optimized Vector3 math. I would need to retest these functions to see if it is still faster to avoid the `sqrt`

19 Likes

So for â€śpos:â€ť do i Need the Position of the playerâ€™s HumanoidRootPart or is it the position of the Sphere?

`pos` is the position of the playerâ€™s HumanoidRootPart.

1 Like

canâ€™t they just do

``````local magnitude = (HRP.Position * Vector3.new(1,0,1) - cylinderPosition * Vector3.new(1,0,1)).Magnitude