Attempt to compare Vector3 < Vector3 error

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

Any help will be appreciated :cowboy_hat_face:

It’s exactly what it says. I assume you just want to see when it reaches that size or grows past it, so you should check component wise:

until fungi.Size.X > 5 and fungi.Size.Y > 5 and fungi.Size.Z > 5
2 Likes

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
2 Likes

Thank you so much! Both of these work, so I don’t know which one to mark as a solution :sweat_smile:

1 Like

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:
image

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:

image

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 a assuming 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:

image

Again, this only holds when each component of the vector is equal.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.