Im using Water4Advance to simulate an ocean waves in Unity3d 5.0. I have my plane displaced in Runtime with Gerstner Displace. I see how the mesh is deformed and i add a MeshCollider to it and i like to refresh this collider mesh in runtime. I was working this on Unity 4.6 with this script:
MeshCollider collider = GetComponent<MeshCollider>();
Mesh mesh = GetComponent<MeshFilter>().mesh;
collider.sharedMesh = null;
collider.sharedMesh = mesh;
But now i only got the flat original plane prefab.
How can i update this MeshCollider with the displaced mesh?
Try this:
Mesh myMesh = this.GetComponent<MeshFilter>().mesh;
DestroyImmediate(this.GetComponent<MeshCollider>());
var collider = this.AddComponent<MeshCollider>();
collider.sharedMesh = myMesh;
From here:
http://answers.unity3d.com/questions/446910/changing-mesh-collider-at-run-time.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With