With the development of my upcoming game I keep getting more issues with my skinned mesh water, and here we are again. I’m using some basic code to move the bones of the skinned mesh upward, and downward to give a wave effect, although using multiple planes of water, the edges do not meet together, despite the script making them do that by getting all of the bones as if treating the multiple plates as one.
local RunService = game:GetService("RunService")
local descendants = script.Parent.Waves:GetDescendants()
local speed = 0
local function Wave(Position)
local amplitude = script.Parent.Amplitude.Value
local frequency = script.Parent.Frequency.Value
speed += script.Parent.Speed.Value / 10^5
local X = amplitude * math.cos(Position.X * frequency + speed)
local Z = amplitude * math.cos(Position.Z * frequency + speed)
return Vector3.new(X, X + Z, Z)
end
RunService.Heartbeat:Connect(function()
for _, descendant in pairs(descendants) do
if descendant.ClassName == "Bone" then
descendant.Transform = CFrame.new(Wave(descendant.Position))
end
end
end)
As I said, I think that by getting all of the bones it should work correctly. If anyone knows how to fix this issue, I’d appreciate the help a ton! Thanks.
Just making sure before I write out a response, your question here is asking why the planes don’t line up at the edges? Or is it that they aren’t all exactly the same? The video doesn’t really show either of these and “they do not sync together” could mean either of the above questions, so just wondering.
Sorry for not being clear enough, the planes are supposed to line up with each other to make a smooth effect, so it basically just looks like one plane.
Something I noticed is that your wave function returns an altered x and z coordinate, which will cause desync problems such as the above. Try changing the function to do
local function Wave(Position)
local amplitude = script.Parent.Amplitude.Value
local frequency = script.Parent.Frequency.Value
speed += script.Parent.Speed.Value / 10^5
local X = amplitude * math.cos(Position.X * frequency + speed)
local Z = amplitude * math.cos(Position.Z * frequency + speed)
return Vector3.new(Position.X, X + Z, Position.Z) --The only changed line
end
And see what happens, I’m also assuming you’ve made sure that the planes are all lined up before you apply the wave.
Odd, when I use that function the plates get practically 2x larger than previously did. I actually fixed that enlargement issue last time by removing that part where you use Position.X and Position.Z
local RunService = game:GetService("RunService")
local descendants = script.Parent.Waves:GetDescendants()
local speed = 0
local function Wave(Position)
local amplitude = script.Parent.Amplitude.Value
local frequency = script.Parent.Frequency.Value
speed += script.Parent.Speed.Value / 10^5
local X = amplitude * math.cos(Position.X * frequency + speed)
local Z = amplitude * math.cos(Position.Z * frequency + speed)
local phi = amplitude * math.cos(Vector2.new(0,0):Dot(Vector2.new(X, Z) - frequency * time))
return Vector3.new(X, phi, Z)
end
RunService.Heartbeat:Connect(function()
for _, descendant in pairs(descendants) do
if descendant.ClassName == "Bone" then
descendant.Transform = CFrame.new(Wave(descendant.Position))
end
end
end)
Ah the time variable needs to be replaced with something more robust. It’s trying to use the time built in function atm. You could try replacing time with time() and see how it goes.
You need to use descendant.WorldPosition, the position variable is relative to the plate meaning bone 0 is the same position on every plate, same going with 1, 2, 3, etc, but WorldPosition is the position in relative to the world meaning, if you place a part and set its position to the world position of a bone, then they will align