Ok just give me 1 hour to do it
This should work!
local yCoordinate = 5 --from where it spawns
while true do
-- sphere equation: x^2 + y^2 + z^2 = r^2
local radius = script.Parent.Size.X/2 -- radius is half of any size coordinate...you can do Y or Z if you wish
local part = Instance.new("Part",workspace)
--setting x^2 + z^2 to equal this
local circleRadiusSquared = math.pow(radius,2) - math.pow(yCoordinate,2)
local longSide
local xCoordinate, zCoordinate
if(part.Size.X>=part.Size.Z) then
local distanceFromSphere = part.Size.X/2
local xMax = math.sqrt(circleRadiusSquared)
local x = math.random(-1*xMax+distanceFromSphere,xMax-distanceFromSphere)
--now we do z
local parabola = math.pow(radius,2)-math.pow(yCoordinate,2)-math.pow(x,2)
distanceFromSphere = part.Size.Z/2
local zMax = math.sqrt(parabola)
local z = math.random(-1*zMax+distanceFromSphere,zMax-distanceFromSphere)
xCoordinate = x
zCoordinate = z
else
local distanceFromSphere = part.Size.Z/2
local zMax = math.sqrt(circleRadiusSquared)
local z = math.random(-1*zMax+distanceFromSphere,zMax-distanceFromSphere)
local parabola = math.pow(radius,2)-math.pow(yCoordinate,2)-math.pow(z,2)
--now we do x
distanceFromSphere = part.Size.X/2
local xMax = math.sqrt(parabola)
local x = math.random(-1*xMax+distanceFromSphere,xMax-distanceFromSphere)
xCoordinate = x
zCoordinate = z
end
part.Position = Vector3.new(xCoordinate,yCoordinate,zCoordinate)
task.wait(3)
end
Don’t know if I did this right but it doesn’t do anything when it put it in a sphere.
This assumes that the sphere is positioned at (0,0,0)
Is your sphere positioned at that? Otherwise, just simply do
part.Position = Vector3.new(xCoordinate,yCoordinate,zCoordinate) + sphere.Position
yup it works. even on cylinders. thanks
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.