# Vector math problem

I am currently running into a slight error involving vector math. The problem I am facing is that I have a planet that is randomly generated using noise values calculated at the vertex position on a sphere, I have come up with a simple method of placing objects on the planet surface at a latitude and longitude.
Here is a picture of what the object does on a planet at the origin (correct positioning): ![alt text][1]
And here is what it does when the planet is not at the origin: ![alt text][2]

Here is the code for this:

``````public Vector3 SurfacePoint(float latitude, float longitude, float raddif, ModuleBase noi, GameObject planetObject)
{

GenerateNoise();
Mathf.Clamp(latitude, -90, 90);
Mathf.Clamp(longitude, -180, 180);
Vector3 spoint;
float lat = latitude * Mathf.PI/180;
float lon = longitude * Mathf.PI/180;
spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon));
spoint.z =  (rad * Mathf.Cos(lat) * Mathf.Sin(lon));

//Vector3 trueplanetPos = spoint - planetPosition;

spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon));
spoint.z =  (rad * Mathf.Cos(lat) * Mathf.Sin(lon));

return (spoint + planetObject.transform.position);
}
``````

The problem I am running into is with the noise value only being correct for a position on the surface of the planet if the planet is located at the origin. The code that I use for getting the noise values is here:

``````void Spherify(float radius, ModuleBase noi)
{
Vector3[] vertices = qMesh.vertices;
Vector3[] verticesN = qMesh.vertices;
Vector3[] normals = qMesh.normals;
Vector3[] truevpos = qMesh.vertices;

for (int i = 0; i < vertices.Length; i++)
{
truevpos _= (transform.TransformPoint(vertices*)) - planetPos;*_
``````

verticesN = (((truevpos.normalized) * (radius + (((float) noi.GetValue((truevpos_.normalized * radius) + planetPos)) * noisemod)))) - (relativePos);

* }*
* transform.rotation = Quaternion.Euler(0,0,0);*
* qMesh.vertices = verticesN;*
* qMesh.RecalculateNormals();*
* qMesh.RecalculateBounds();*
* }*
The most important part of that code is here this bit