Fluid Animation

This is honestly pretty cool! Though I think this is abit unoptimized and could potentially cause a lot of lag. You should try using skinned meshes for better & smoother results ^

1 Like

I’m not familiar with meshes, are there any resources that you could show me about how to use meshes and skinned meshes?

You would add more comments and explain your code next time

I don’t know what you mean, I have explained it?

3 Likes

Yea sure! Here is an example of ocean waves simulation using skinned meshes 2020 10 09 19 37 09 - YouTube
I can’t really find more of an informative stuff sorry! You could possibly do some research on skinned meshes if you would like to achieve these certain effects ^ ^

Overall, good job! :+1:

However, the system makes quite a dent in performance. There are some improvements I think you should take into consideration (there might be more, but this might help):

  • Try to avoid using while true do if you can because of this.
  • If this will be used in games, move your code to the client: visuals like these (especially constantly updating CFrame and position for animations) should be on the client so the server doesn’t have to bother computing and replicating any of that.
  • If you use RunService to replace the loop and you’ve moved it to the client, make use of deltaTime when determining how much to move everything.
  • Keep it small: if this will be in a game, updating this many parts so often can create a large performance impact so I don’t recommend keeping the grid too big (this is more of a suggestion for those utilizing the system).
  • Try to cut down on the amount of calculations you are doing each iteration of any loop and take into consideration how you have loops inside loops - you might even need to restructure the system to limit how many total iterations that every loop goes through (with enough work, I’m sure you can figure something out).

Lastly, some quick possible code improvements:

  • Comment your code for newer developers! Even if you understand what certain parts do, that doesn’t mean somebody else would.
  • Lines like these var = var + number can be replaced with var += number. Read about that here.
  • Add some spacing in your code: separate a constant stream of lines with the occasional double new line to visually separate different parts of your code (this is the way I prefer to do it, but it can really be done any way - see below for example).

Code spacing example

Side note: code spacing can also help make room for commenting chunks of your code!

local function GetBlock(Name) 
	local Block = LevelGrp:FindFirstChild(Name)
	
	if(Block == nil) then
		Block = Instance.new("Part",LevelGrp)
		Block.Size = Vector3.new(BlockSize,BlockSize,BlockSize)
		Block.Material = Enum.Material.SmoothPlastic
		Block.BrickColor = BrickColor.Blue()
		Block.Anchored = true
		Block.CanCollide = true
		Block.Name = Name
		Block.Transparency = BaseTransparency
		
		local Faces = {"Left","Right","Top","Bottom","Back","Front"}
		for i,v in pairs(Faces) do
			Block[v.."Surface"] = Enum.SurfaceType.SmoothNoOutlines
		end
	end
	
	return Block
end

I hope this feedback helps!

4 Likes

Thank you for the feedback. I will be sure to try and add these things.

Thanks, I have seen that article but I will keep looking.

Did you use some math formula equation?

Or did you just do that with your experience?
If “yes” could you tell me how I can learn to get into that result?

Great job. Moving water is tough!

Thanks! I know it definitely is.

1 Like

I had made something similar to this in the past and basically I just varied the perlin “density” (the inputs you give the math.noise function) to give it the “illusion” of it moving.

Wow! That looks very smooth. I am currently trying to port my one to a Plane Mesh.

I’ve heard that the trick is to create “bones” for each point we generate

Yes, but the problem is when I do a For Loop to create the bones, the Plane Mesh does not deform. I made a thread about it. But I have still not found a Solution.

I have made something similar to that in the program itself but not in roblox. Basically you need to create its end state in the program then play whats called literally a “Mesh Deform Modifier”. You then set the keyframe state to 1 then move the meshes verticies save the keyframe then u can animate its state in the program. Perhaps what you could do is animate it from 0 to 1 and expand it to the perlin range.

Would you mind explaining that a bit more simple. I have been using Blender for 1 day, so I am very new.

Do you understand the idea of interpolation?

To be honest to not really. Never read up on it.

In most simplest terms it is the concept of taking 2 values and mapping them to a range, so say we have 5 and 10 and our “alpha” is at 0.5 (the domain of alpha is 0 to 1). That would mean our alpha would return 7.5. Now we can expand this to 3d by simply interpolating each position component in our vertices.