My first thought was trying to inscribe a cube around a sphere but then I just realized that there is a much simpler solution.
So instead of just using (CurrentPos-InitalPos).Magnitude, which would give you a sphere, you can just check each axis, and use whichever one is bigger.
Something like:
local DeltaPosition = CurrentPos - InitalPos -- Get the delta
local DeltaX = math.abs(DeltaPosition.X)
local DeltaZ = math.abs(DeltaPosition.Z)
local DistanceFromCenter
if DeltaX > DeltaZ then -- check for which is bigger and use that for the distance.
DistanceFromCenter = DeltaX
else
DistanceFromCenter = DeltaZ
end
print(DistanceFromCenter)
This doesn’t check for your Y position, but you can add that into the conditional if you really need to.
Also, correct me if I’m wrong but I think the original DOOM had this exact method for explosion checks too.