Help understanding math.noise

hey, so i found a script that i modified a bit:

local curIter = 0
local amplitude = 5

while task.wait() do
	curIter += 0.005
	for _, wave in workspace.Plane:GetChildren() do
		if wave:IsA("Bone") then
			local x = wave.Position.X
			local z = wave.Position.Z

			print(math.noise(x/20+curIter, z/20+curIter) * amplitude)
			wave.Position = Vector3.new(x, math.noise(x/20+curIter, z/20+curIter) * amplitude, z)
		end
	end
end

and this is basically to make ocean waves using bones:
2025-01-2122-40-06-ezgif.com-video-to-gif-converter

the thing im not understanding is why we have to constantly add curIter, i checked the noise value of just one bone using the print above, and it goes back and forth between like 5 and -5 constantly, despite curIter constantly rising

if anyone knows how this works it would be great, because I cant figure what changing the value of curIter does

When you call math.noise it returns a value that is constant when the same arguments are passed in. For example, calling math.noise(1.25, 5.75) will always return 0.5098056793212891. This acts a bit like a sine wave (y = sin(x)), where nearby inputs yield nearby results.

In the code sample you provided above, curIter is slowly increased to produce the wave effect. If you removed curIter the waves would be static at all points. Since curIter is added to each node’s position (and curIter is slowly increasing) the noise function at each node slowly shifts between -1 and 1, which is then multiplied by amplitude - this is why you see it shifting between -5 and 5.

oh alright so if im understand correctly with math.noise its the difference between the numbers that matters and not how big the numbers are, and because the 2 positions are always a bit different you get a range of numbers

and then + or - depends on how big it is

lmk if thats about right

Assuming you’re talking about two different calls to math.noise you’re correct that the difference between the passed arguments is what matters for how much the result changes. I’m not sure what you mean in the rest though, so I’ll leave this tutorial video about Perlin noise (the algorithm behind math.noise) from a channel that makes lots of other helpful coding tutorials as well!

The Coding Train, “I.5: Perlin Noise - The Nature of Code”

1 Like