How can I make my 2D waves look good.

Hello! I have 2D waves I’m working on. I can choose how many vertices are on top (the part that moves to look like a wave) and scale up or down this wave object. I tried to make the waves move but it looks very sharp and not achieving what I want. I did some perlinnoise and it either made it look VERY smooth to the point where it looked like it was moving to the left. Or it looked very jagged. The in between look I got was a low poly style look. I want a smooth yet random looking wave. I tried adding random values to the perlin noise and I tried sin and all of that but I guess I’m doing it wrong. Also one more thing… the Y value of the wave max can go 100 and min can go 0 because of the way the waves are drawn. Thanks!

EDIT: I tried to do something like this but I couldnt understand the java script very well.

EDIT: If you scroll down you see what I was trying to achieve. I got the waves drawn and Im able to edit the vertices positions but I can’t seem to make it look right.

What exactly have you tried so far? I mean concrete, not as abstract as you said it in your question. You said you “tried to make the waves move”. What exactly have you tried? What actually is a wave in your mind? You linked that gamedev question which as several answers. Regardless if you can read LUA or not the answer actually has a quite detailed description in plain english what he did in each step. You only mentioned waves while the article is actually about an almost complete 2d fluid dynamics simulation (interaction when dropping something into the water). If you just want waves, just add together a bunch of sine waves. As you can read in the answer you’ve linked, just use different frequencies, phases and amplitudes. Note that it probably helps when you have at least one sine wave that goes in the opposite direction. Just as in real life water ripples are usually many small wave systems with different frequencies and directions.

For example:

public static float Wave(float xPos, float frequency, float amplitude, float phase, float speed)
    return amplitude * Mathf.Sin(frequency * (xPos + phase + Time.time*speed));

The x position of each vertex wouldn’t change at all. You just calculate a new y position based on several “Wave” calls which you add together. I specifically did not use any constant factors (like 2 * PI) since it’s pretty irrelevant, You just need to adjust the wave parameters until it looks ok for you. You can simply put those parameters into a class and adjust the values in the inspector in realtime.

public class WaveSettings
    public float frequency = 1;
    public float amplitude = 1;
    public float phase = 0;
    public float speed = 1;
    public float Evaluate(float xPos, float time)
        return amplitude * Mathf.Sin(frequency * (xPos + phase + time*speed));

Now just put this into a MonoBehaviour:

public WaveSettings[] waves;

public float EvaluateVertex(float xPos)
    float res = 0;
    foreach(var w in waves)
        res += w.Evaluate(xPos, Time.time);
    return res;

Now you can call “EvaluateVertex” for every vertex to calculate the new height for this vertex. Of course how many sine waves and which parameters make sense / look good is up to you. Just tweak them in the inspector. I recommend at least 3 different waves.

@Bunny83 Yes I’m trying to simulate splashes because I plan to have game objects interact with the water. Originally I had just used perlin noise to get waves which worked but if I had ALOT of points for the waves it looked very messy and jagged. I wanted the waves to look some what the same to that link I posted that that user showed that video. The guy who answered it did what the asker wanted atleast to what I can see and thats what I want as well. I was having trouble reading the code and translating it to my situation with vertices.

Really what I’m trying to say here is that answer in that link is exactly what I want and even with his explanation I cannot figure it out and thats what I need help with. Simulating splashes and adding to the normal wave ‘animation’ without things looking wonky.