# Modify mesh problems

Hello, I’ve recently asked myself how could I make a random planet and my quick answer was modify the verts of a sphere randomly, but now, it is taking a lot of pain.

after some research this is my code:

``````	Mesh mesh;
Vector3[] verts;
Vector3[] normals;
Vector3 WorldPosition;
void Awake(){
mesh = GetComponent<MeshFilter>().mesh;
verts = mesh.vertices;
normals = mesh.normals;
for (int i=0; i<verts.Length; i++) {
verts <em>+= normals _* Random.Range(1f,1.2f);_</em>
``````

* }*
* mesh.vertices = verts;*
* mesh.normals = normals;*
* mesh.RecalculateNormals ();*
* mesh.RecalculateBounds ();*
* mesh.Optimize ();*
* }*
I use it on a sphere and a plane to check if its correct, in the plane it seems that there is no problem.
Plane before and after code:
[28993-plane+guay.jpg|28993]_
_
But in the sphere something goes very wrong:
![alt text][3]
![alt text][4]
it seems like the verts are duplicating or something weird, I tried Mesh.Clear() but that doesn’t work.
Anyone have an idea how I can fix it?
Thanks
_*
_*
_[3]: http://i59.tinypic.com/30lfatu.jpg*_
_
[4]: http://i59.tinypic.com/2mevomo.jpg*_

After thinkin a few hours more this is my solution.

``````for (int i=0; i<verts.Length; i++) {
tempVert=verts*;*
``````

if(verts_!=initVerts*){
Debug.Log (“this vert has been already modified”);
continue;
}_
verts += normals _ Random.Range(1f,1.2f);
* for(int j=0; j<verts.Length;j++){
if(i==j){
Debug.Log (“its the same vert”);
continue;
}else{
if(verts[j] == (tempVert)){
Debug.Log (“Double vert”);
verts[j]=verts;
}
}
}
}*_