Is this script functional?
local sphere = script.Parent.Butterfly
function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end
function moveButterfly()
local dx = math.random(-100,100)
local dy = math.random(-40,40)
local dz = math.random(-100,100)
if (sphere.Position.y < 10 and dy < 0) then dy = -dy end
if (sphere.Position.y > 80 and dy > 0) then dy = -dy end
local vec = computeDirection(Vector3.new(dx,dy,dz))
sphere.BodyPosition.position = sphere.Position + (vec * 40) -- change this number to alter speed
end
while true do
moveButterfly()
wait(1)
end
I’m not asking if it is well written, I’m asking if it is functional