How do I update a mesh physics?
I used this code:
using UnityEngine;
using System.Collections;
public class WaveGen : MonoBehaviour
{
float scale = 0.1f;
float speed = 1.0f;
float noiseStrength = 1f;
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();
}
}
From this thread: http://answers.unity3d.com/questions/443031/sinus-for-rolling-waves.html
To create waves. The problem I'm having, is that I don't know how to update the physics, so that the player properly collides with the waves. What should I do?
Comment
Your answer
Follow this Question
Related Questions
Edit SkinnedMesh with vertices 0 Answers
How to partially change texture? 0 Answers
Add vertex position by it's axis 1 Answer