How to simulate waves in Unity?

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?


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;

but if you want simulate swim you can use this link

Category: unity Time: 2016-07-30 Views: 1
Tags: unity

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.138 (s). 12 q(s)