# Position waypoint along sphere

Hi everyone I need your help. I’m trying to create a waypoint system on a spherical world. That’s what I got. The cubes are waypoints ranging from enemy to player direction. Now I have to make sure that the cubes are placed on the spherical surface. I’m trying to use breast and cosine but missing something to make it work. Here is the code with the drawing

Here I add the various waypoints

``````![public Transform t1, t2, node, planet;
public int division;
private List<Transform> nodes;
Vector3 direction, nodeDirection;
float dist, result;
void Start ()
{
nodes = new List<Transform>();
dist = Vector3.Distance(t1.position, t2.position);
direction = (t2.position - t1.position).normalized;

for (int i = 0; i < division; i++)
{
result = (dist / division) * i;

//
Transform t = Instantiate(node, new Vector3(GetPos(direction.x, result, t1.position.x),
GetPos(direction.y, result, t1.position.y),
GetPos(direction.z, result, t1.position.z)),
Quaternion.identity) as Transform;
}

float GetPos(float axis, float result, float player)
{
return (axis * result) + player;
}
}]
``````

should be simple as getting the distance from the center of your circle to the ouside which it looks like have in the top of your script.

then multiply the NORMALIZED directions for all your objects by the consistant distance. Then just add it to the circles center position for the new objects positions!! here is a generic working example to show the math steps:

``````	GameObject g;
Vector3 center= Vector3.zero;
float dist = 5;

int i = 50;
while (i>0) {i--;
// get some random directions
Vector3 v = new Vector3(
Random.Range(-10f,10f),
Random.Range(-10f,10f),
0);
v=v.normalized;
v=v*dist;
g= GameObject.CreatePrimitive(PrimitiveType.Cube);
g.transform.position=v+center;
}
``````