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?
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?
https://docs.unity3d.com/ScriptReference/Mesh-vertices.html
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;
mesh.RecalculateNormals();
}
}
when somebody swim in water he create wave in water you should follow two link for more information about it:
you can easily create wave based on this gif in 3D
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