I want to implement a A* algorithm in my game, which takes place on a planet. I generated evenly distributed points with the Code below and my wish is to create connections between a point and about 3-5 others points. One connection ist going to be a possible path with a weight, which is it's distance. I need to connect all Points in a way(maybe the neares Points?), so i can pathfind from any point to any others point in the sphere.
`Vector3[] GetPointsOnSphere(int nPoints)
{
float fPoints = (float)nPoints;
Vector3[] points = new Vector3[nPoints];
float inc = Mathf.PI * (3 - Mathf.Sqrt(5));
float off = 2 / fPoints;
for (int k = 0; k < nPoints; k++)
{
float y = k * off - 1 + (off / 2);
float r = Mathf.Sqrt(1 - y * y);
float phi = k * inc;
points[k] = new Vector3(Mathf.Cos(phi) * r, y, Mathf.Sin(phi) * r);
}
return points;
}`
Any ideas how to do this?
![alt text][1]
[1]: /storage/temp/165840-sphere.png
↧