Detect if player is inside a sphere zone

I have an ability that spawns a huge sphere and the players inside it should experience an effect

But what’s the MOST EFFICIENT way of detecting it?

I know about bounding box thingy but im not sure if that works for a sphere?

Could probably use this

Alternatively, you can loop through all the players characters and check if the (CenterOfSphere - HumanoidRootPart.Position) < RADIUS, and if so then apply the effect. Dunno if this is very efficient though

2 Likes

Interesting, didn’t know about this function, it asks for a radius tho, how do i get the radius of the sphere i have?

Well how is the sphere created?

image

In the script where you will try to access the sphere, how is the sphere defined? (put the code)

I’d recommend you do:

The hitBox is the sphere zone in your case

But that requires cantouch to be on right?

Nope it can be false and it will still work

not entirely sure what u mean… but

local function DetectLocalPlayerHit(part)
	workspace:GetPartBoundsInRadius(part.Position)
end

The radius of the sphere is just half the width (or height, or depth). So radius would just equal:

local Radius = Part.Size.Y/2

Note that this assumes that all dimensions are equal.

If they are not, use this instead:

local Radius = math.min(Part.Size.X Part.Size.Y, Part.Size.Z)/2

Worked like a charm!

(Excuse the video lag I had to run 3 roblox studio instances on my old computer I could literally smell my CPU melting)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.