How is it possible to simulate water in our game?

I want to make rivers and lakes for my game but I don't know how to make the waves and make the water look like it's moving.

How would I do it?

  • \$\begingroup\$ There are three separate questions here which you should ask separately: 1. how to make water which looks good (material and shader settings), 2. how to generate waves in a mesh (this is the only part of the question which already got an answer) and 3. how to change an animation from walking to swimming when a characters enters water (you might want to add if you are talking about a sprite or a rigged 3d model). \$\endgroup\$
    – Philipp
    Jul 30 '16 at 16:09
  • \$\begingroup\$ @Philipp thanks philipe for your comment. I hope you have good answer for it \$\endgroup\$
    – virtouso
    Jul 30 '16 at 16:13
  • \$\begingroup\$ I might have an answer from one of these questions, but I won't consider writing an answer unless you create it as a new question and add sufficient details. \$\endgroup\$
    – Philipp
    Jul 30 '16 at 16:16


Returns a copy of the vertex positions or assigns a new vertex positions array. The number of vertices in the mesh is changed by assigning a vertex array with a different number of vertices. Note that if you resize the vertex array then all other vertex attributes (normals, colors, tangents, UVs) will be automatically resized too. RecalculateBounds will automatically be invoked if no vertices have been assigned to the mesh when setting the vertices.

this is sample wave simulate by using Mesh vertices

using UnityEngine;
using System.Collections;

public class WaveGen : MonoBehaviour
  public float scale = 0.1f;
  public float speed = 1.0f;
  public float noiseStrength = 1f;
  public float noiseWalk = 1f;

  private Vector3[] baseHeight;

  void Update () {
    Mesh mesh = GetComponent<MeshFilter> ().mesh;

    if (baseHeight == null)
      baseHeight = mesh.vertices;

    Vector3[] vertices = new Vector3[baseHeight.Length];
    for (int i=0;i<vertices.Length;i++)
      Vector3 vertex = baseHeight[i];
      vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].x + baseHeight[i].y + baseHeight[i].z) * scale;
      vertex.y += Mathf.PerlinNoise(baseHeight[i].x + noiseWalk, baseHeight[i].y + Mathf.Sin(Time.time * 0.1f)    ) * noiseStrength;
      vertices[i] = vertex;
    mesh.vertices = vertices;

when somebody swim in water he create wave in water you should follow two link for more information about it:

1.wave in 2D game

you can easily create wave based on this gif in 3D

enter image description here

2.wave in 3d game

Unfortunately you can not simulate water because at any moment millions of particle to be simulated because game is Realtime(while you can do it for animations by simulating likeRealflow because there is enough time to calculate rendering). It will create lag in your game ,I prefer you use shader in your game.

Shaders are small scripts that contain the mathematical calculations and algorithms for calculating the colour of each pixel rendered, based on the lighting input and the Material configuration. https://docs.unity3d.com/Manual/Shaders.html

enter image description here

Scrolling textures by modifying UV values

Water surface ripple effect for Unity

  • \$\begingroup\$ thanks for your answer. but what about river? if I want a certain shape of river. should I beuild it in 3d app and import it? is there anyway to make mesh in unity? im going to accept your answer \$\endgroup\$
    – virtouso
    Jul 30 '16 at 16:12
  • 1
    \$\begingroup\$ I using real flow for simulating water but I don't prefer it in unity because of many processing and calculating same rendering by Vray.I am sure that many game use basic simulating water for example battlefield 4 used many water shader instead of simulating it. \$\endgroup\$ Jul 30 '16 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.