Hello! I am trying to make an advanced fungus ai (similar to the one a roblox dev named Cone made). This fungus ai includes parameters of rate and iq. However, when I’m trying to check if the fungus has reached a certain size, it seems to not work.
Here is the code:
local function fungus_ai(parent, rate, iq)
--fungi
local fungi = Instance.new("Part")
fungi.Material = Enum.Material.Ground
fungi.BrickColor = BrickColor.new("Parsley green")
fungi.CanCollide = false
fungi.Position = parent.Position
fungi.Size = parent.Size / 1.5
fungi.Parent = parent
--weld
local weld = Instance.new("WeldConstraint")
weld.Parent = fungi
weld.Part0 = parent
weld.Part1 = fungi
--rate
if rate >= fast_rate then
if rate > 0.9 then
repeat
task.wait(rate)
fungi.Size += Vector3.new(0.25, 0.25, 0.25)
until (fungi.Size > Vector3.new(5,5,5)) --attempt to compare Vector3 < Vector3
else
end
end
end
You could always just check the Magnitude property of the Vector3 divded by sqrt(3) if you know for a fact the part will scale equally on all three axes.
Reason being: the magnitude of a vector (a, a, a) is simply sqrt(3) * a. Since the magnitude of a vector with components (5, 5, 5) is equal to 5 * sqrt(3), just divide the Magnitude by sqrt(3) to check if its components are all 5.
-- rate
if rate >= fast_rate then
if rate > 0.9 then
repeat
task.wait(rate)
fungi.Size += Vector3.new(0.25, 0.25, 0.25)
until (fungi.Size.Magnitude / sqrt(3) > 5)
else
end
end
I was merely expanding on @Pokemoncraft5290’s solution that only works in a specific case. As an elaboration on why it even works:
Observe the formula for the magnitude of a vector with n components:
This equation essentially boils down to “take the square root of the sum of each squared vector component.”
When a_1, a_2, a_3, ..., a_n are all the same, the equation becomes this:
This is simply the result I discuss, which stems from the fact that you are adding n copies of a^2 under the root. Therefore, to check when a vector’s components are all equal to aassuming you know they will scale equally and uniformly, just divide the magnitude of the vector by the square root of the number of components, which is n:
Again, this only holds when each component of the vector is equal.