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.
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