Creating my own waves, anyone have any tips to improve this?

I am trying to use Gerstner Wave Function to animate waves.

The waves only animate server side

I cannot figure out any solution

Was following this Youtube video to get the math:
Coding Adventure: Gerstner Waves - YouTube

My code:

-- Using Gerstner Wave function to animate plane

local plane = script.Parent.Plane

local bones = plane:GetChildren()
table.sort(bones, function(a,b) return a.Name < b.Name end)

-- Using Gerstner Wave function to animate plane

local tweenTime = 5 -- time between waves

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear)

local startTime = os.clock()

while true do
	
	for key, value in bones do
		
		local deltaTime = os.clock() - startTime
		
		deltaTime *= script:GetAttribute("Speed")
		
		x = math.cos(key-deltaTime)+key
		
		y = script:GetAttribute("Amplitude") * math.sin(x-deltaTime)

		local vector = CFrame.new(Vector3.new(0,y,0))
		
		value.Transform = vector
		
		--TweenService:Create(value, tweenInfo, {Transform = vector}):Play()

	end
	task.wait()
end

Video of current results:

2 Likes

Your problem is the waves only animating server side right?
.Transform on bones and motor6d’s are only visible to whoever set them, it doesn’t sync between server or individual clients.

Something about the waves look unnatural too, it’s all one texture that doesn’t move, it looks very out of place.

1 Like

Yeah, I know it looks a little unnatural. This is my first time making waves.

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