Hi! I’m pretty new to Perlin Noise, just started watching videos on it today. My goal is to make wavy water for a river so I can bring some life to my low-poly world.
To be clear, this isn’t a 3D system, but a 2D system, which I guess could be tricky since math.noise()
uses 3 values?
I’m using beams to connect the nodes instead of parts. It’s just a line of nodes all in one direction, spaced out, connected by beams that are all at a fixed width.
local GROUP = workspace.WaterGroup --Where all the nodes are stored
local ORIGIN = GROUP.Origin --The first node is positioned
local WIDTH = 150 --Width of the water
local SCALE = 25 --Distance between each node
local NODES = 40 --The amount of nodes
local COLOR = Color3.fromRGB(0, 85, 255) --The color water desired
local POWER = 3 --The amount of force in the waves
local yOffset = 0
local function setAttach(x) --Create an attachment to serve as a Node
local newAttach = Instance.new("Attachment", ORIGIN)
newAttach.Name = x
newAttach.Position = Vector3.new(x * SCALE, 0, 0)
return newAttach
end
local function setPoints() --Create the line of Nodes
local points = {}
for x = 0, NODES do
local newAttach = setAttach(x)
table.insert(points, newAttach)
end
return points
end
local function setBeams(points) --Set beams between the Nodes
for num, point in pairs(points) do
if num > 1 then
local newBeam = Instance.new("Beam", point)
newBeam.Attachment0 = points[num - 1]
newBeam.Attachment1 = point
newBeam.Width0 = WIDTH
newBeam.Width1 = WIDTH
newBeam.Color = ColorSequence.new(COLOR)
newBeam.Transparency = NumberSequence.new(0)
end
end
end
local waterPoints = setPoints()
setBeams(waterPoints) --Generate the points and their beams
This script creates a nice, flat plane of beams all connected to one another. My main issue is making them move up and down in a wave-like motion.
local function calculateHeight(x, y) --Calculate the height of each point through Perlin noise
local xCalc = x
local yCalc = y + yOffset
return math.noise(xCalc, yCalc)
end
while true do
local dt = Heartbeat:Wait()
for _, point in pairs(waterPoints) do
point.Position = Vector3.new(point.Position.X, 0, calculateHeight(point.Position.X, point.Position.Z) * POWER)
yOffset = yOffset + .1 * dt
end
end
This is the result when I do it this way. It’s rather fast and glitchy, but at least the nodes move up and down.
robloxapp-20200527-1727012.wmv (497.5 KB)
I’ve tried looking at many setups for Perlin noise but I just can’t figure out how to get it to behave right. Would anyone know how to properly do this?