- Home /

**closed**Dec 17, 2012 at 08:21 AM by Fattie for the following reason:

The question is answered, right answer was accepted

# TransformPoint trouble

I have 2 scripts, one that is added straight to the GameObject to change its mesh,and the same script in a function and it changes the mesh of other game objects. the 2nd code changes the mesh but it seems to ignore the transform.transformpoint function.

This one works:

```
private var org = Vector3.zero;
var basescale =3;
//var currentobject = gameObject;
private var vtxArray : Vector3[];
var radius = 100;
var transition = 50;
function Start () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var scale = basescale;
if (vtxArray == null)
vtxArray = mesh.vertices;
var objectscale = (gameObject.transform.localScale);
var vertices = new Vector3[vtxArray.Length];
for (var i=0;i<vertices.Length;i++)
{
//var vertex = vtxArray[i];
vtxArray[i] = transform.TransformPoint(vtxArray[i]);
var vertex = vtxArray[i];
var dist = Vector3.Distance(org, vtxArray[i]);//lines that set mutation in a bubble and smooth edges
if ( dist > radius ){ scale = 0*basescale;}
if ( dist <= radius && dist >= radius-transition) {scale = ((radius-dist)/transition)*basescale;}
if ( dist < radius-transition ){ scale = 1*basescale;}
vertex.x += Mathf.Sin(vtxArray[i].y*.1 + vtxArray[i].z*.1) * scale;
vertex.y += Mathf.Sin(vtxArray[i].z*.1 + vtxArray[i].x*.1) * scale;
vertex.z += Mathf.Sin(vtxArray[i].x*.1 + vtxArray[i].y*.1) * scale;
vertices[i] = transform.InverseTransformPoint(vertex);
//Debug.Log (vtxArray[i]);
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
DestroyImmediate(collider);
gameObject.AddComponent("MeshCollider");
//gameObject.GetComponent(MeshCollider).sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
}
```

this one doesn't work:

```
function sinus1 ( multiplier:int ){//this function takes mesh objects and changes their vertices in XY and Z into mountains
//var process : Collider[] = Physics.OverlapSphere(selzone.transform.position, selzone.transform.localScale*1.1;);
var mymeshfilters : MeshFilter[] = FindObjectsOfType(MeshFilter) as MeshFilter[];
for (var mymeshfilter in mymeshfilters) {
var mydistance = Vector3.Distance(selzone.transform.position, mymeshfilter.transform.position);
//print( mydistance );
if ( mydistance < selzone.transform.localScale.x * .5 && mydistance!= 0){
//mymeshfilter.gameObject.AddComponent ("noisemesh");
var org = selzone.transform.position;
var basescale =3;
//var currentobject = gameObject;
var vtxArray : Vector3[];
var radius = transform.localScale.x * .5;
var transition = transform.localScale.x * .25;
var mesh : Mesh = mymeshfilter.mesh;
print( mesh.vertices.length );
var scale = basescale;
if (vtxArray == null)
vtxArray = mesh.vertices;
var objectscale = (gameObject.transform.localScale);
var vertices = new Vector3[vtxArray.Length];
for (var i=0;i<vertices.Length;i++)
{
//var vertex = vtxArray[i];
vtxArray[i] = transform.TransformPoint(vtxArray[i]);
var vertex = vtxArray[i];
var dist = Vector3.Distance(org, vtxArray[i]);//lines that set mutation in a bubble and smooth edges
if ( dist > radius ){ scale = 0*basescale;}
if ( dist <= radius && dist >= radius-transition) {scale = ((radius-dist)/transition)*basescale;}
if ( dist < radius-transition ){ scale = 1*basescale;}
vertex.x += Mathf.Sin(vtxArray[i].y*.1 + vtxArray[i].z*.1) * scale;
vertex.y += Mathf.Sin(vtxArray[i].z*.1 + vtxArray[i].x*.1) * scale;
vertex.z += Mathf.Sin(vtxArray[i].x*.1 + vtxArray[i].y*.1) * scale;
vertices[i] = transform.InverseTransformPoint(vertex);
//Debug.Log (vtxArray[i]);
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
DestroyImmediate(collider);
gameObject.AddComponent("MeshCollider");
//gameObject.GetComponent(MeshCollider).sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
}
}
}
```

**Answer** by MountDoomTeam
·
Dec 17, 2012 at 04:21 AM

```
vertices[i] = transform.InverseTransformPoint(vertex);
vertices[i] = transform.TransformPoint(vertex);
```

the above 2 lines have the error, I didn't specify from what objects to calculate the transform point, if I am messing with a 3rd party GameObject I should be writing

```
vertices[i] = 3rdpartyobject.transform.InverseTransformPoint(vertex);
```

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.