Greetings,
For the past few days I’ve been trying to make a custom water system for my game, starting with Gerstner Waves. My code stems from this tutorial however the code is pretty much the same (as in it’s been mirrored to Roblox). Upon testing today I found that the waves would stretch in very peculiar axis:
It reflects the correct behaviour however it is on the wrong axis and to put it bluntly I’m stumped. I’ve tried alternating between compound operators but to no avail.
Code
local runService = game:GetService("RunService")
local configuration = script.Configuration
local sizeX = configuration.SizeX.Value
local sizeY = configuration.SizeY.Value
local resolutionConfig = configuration.Resolution.Value
local positionConfig = configuration.Position.Value
local amplitude = configuration.Amplitude.Value
local waveLength = configuration.WaveLength.Value
local speed = configuration.Speed.Value
local gridCreator = require(script.GridCreator)
local grid = gridCreator.new({
Size = Vector3.new(sizeX, 5, sizeY),
Position = positionConfig,
Resolution = resolutionConfig,
DrawType = "WedgePart"
})
while wait() do
for x = 1, grid.Resolution do
for y = 1, grid.Resolution do
local wave = 2 * math.pi / waveLength
local formula = wave * (y - speed * os.clock())
local tangent = grid.Position:Dot(Vector3.new(
1 - wave * amplitude * math.sin(formula),
wave * amplitude * math.cos(formula),
0
)
)
local normal = Vector3.new(-tangent, tangent, 0)
grid.Points[x][y].X += math.clamp(amplitude * math.cos(normal.x), 0, math.pi * 2)
grid.Points[x][y].Y = math.clamp(amplitude * math.sin(normal.y), 0, math.pi * 2)
end
end
end
(this uses boatbombers fantastic gridcreator module)
I’d be extremely grateful for any help at the moment, thank you in advance.