I am trying to figure out how to check if a part is within a ball part (sphere) using magnitude, but I can't figure out the correct math. Any help would be appreciated heavily.
COMMUNITY QUESTION
How would I check if a part is within a sphere (ball) with magnitude?
2 answers
I recommend using GetTouchingParts, using Magnitude has more math in it, GetTouchingParts is simpler and easier, magnitude takes up a few extra lines...
local p = workspace.Part.Position.Magnitude
local p2 = workspace.OtherPart.Position.Magnitude
if math.abs(p-p2)<p-workspace.Part.Size.X then -- a sphere size has to be the same for x,y,z I believe.
print('colliding')
end
-- I really don't know if this will work or not, looks fine to me though
I am using abs because sometimes it glitches for me, It is believed that magnitudes can never be negative but I really don't know.
You didn't give code so I didn't give precise results, if this helps though, click answer. c:
local Sphere=workspace.Sphere
local Part=workspace.Part
if (Part.Position-Sphere.Position).Magnitude<=Sphere.Size.Magnitude/3 then
print'Part is Inside of Sphere!'
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
I am using this for damaging players in a sphere explosion, and using gettouchingparts on a very big explosion is an issue (yes I tested), so that is why I am asking
I ended up figuring this out myself, but thanks for trying to help!
Good job!!