- Home /
adding a mesh collider to this heightmap script properly
im looking into this procedural heght map script and im trying to figure out how to ad a meshcollider to it properly at run time , ive tryed diferrent ways to do it myself but i think im not getting the data from the mesh variable correctly , here is the script http://pastie.org/1744643 (its from the procedural example project) this is my version of it http://pastie.org/1745073 but its far from doing what i want it to could anyone point me in the right direction ?
Answer by Parthon · Apr 01, 2011 at 10:10 PM
I'm really not sure what you were trying to do when you changed the script.
A MeshCollider relies on a Mesh component, like in the first script. You seem to have changed the Mesh to MeshCollider, which would cause it to fall apart. The solution is to add both a Mesh and a MeshCollider, but it's better to add the MeshCollider after the Mesh is generated.
What you have to do is use the original script, then just add gameObject.AddComponent(MeshCollider); at the bottom of the GenerateHeightmap() function.
If the script is already working properly, that's all you have to do.
Your answer