Hello, guys. I’m trying to find a efficient way to make sea waves, and it seems that i’m stuck. I try different approaches - Shaders, Bones and Rebuilding with script.
I didn’t manage to get enough control with shader, as i did with rebuilding, but i really can’t handle such big GC.
Can any one give me a suggestion on this? What is the right way to do some thing like that?
Modifying a mesh with a script doesn’t require any rebuilding or GC. All you need is to keep the Vector3 array for the vertices, and upload that (with mesh.vertices = myVertices) when necessary.
Hi,
I’ve done something similar to waves (in fact I was just plotting some math functions such as sine and cosine) and I managed to obtain a nice waving motion by creating a particle system and by moving the particles. try something like this:
Create a particle system
Create a script that create the particles and alter their position over time and attach it to the particle system.
Here’s a sample (c#) to get you started:
variables:
private ParticleSystem.Particle[] points;
void Start()
{
points = new ParticleSystem.Particle[number of particles];
}
void Update()
{
// Alter your particles here, set their position, color etc
// like this points_.position, points*.color etc*_
// update the particle system particleSystem.SetParticles(points, points.Length); } this way you should avoid gc altogether as you’re only modifying the particles position, then it is just a matter of using a nice watery shader for the particles