Hello everyone, To not bore you with details ill go strait to the problem, i want to create a poligon where the player can input the amount of verts it has. for now i just want to create the points in 3d space.
To do this I tried to get the internal angle of the poligon dividing 360 by the # of vertices, then used that angle with the radius to create a vector and obtained its x and y components (all in 2d space so y is actualy z in 3d space) finaly to test it i created a cube at each point
problem is some odd things are happening: the distance from the center is accurate but the distance between a vert and its adjacent points is not always the same as if it had the wrong angle
here is the code:
public int verts;
public float radius;
public List <Vector3> points = new List<Vector3>();
void Start ()
{
CreateCircle();
}
void CreateCircle ()
{
//points.Add(new Vector3(0, 0, 0));
float ang = 360/ verts ;
for (int i = 0; i < verts; i++)
{
//calculate the angle between points
float cAng = ang * i;
print ("ang" + ang);
Vector2 ornt = Vector2.zero;
//calculate the points x and z position
float x = Mathf.Abs(radius * Mathf.Cos(cAng));
float z = Mathf.Abs(radius * Mathf.Sin(cAng));
if (cAng <= 90) ornt = new Vector2(1, 1) ;
else if (cAng <= 180) ornt = new Vector2(-1, 1) ;
else if (cAng <= 270) ornt = new Vector2(-1,-1) ;
else if (cAng <= 360) ornt = new Vector2( 1, -1) ;
print ("orient" + ornt);
//add the points to a List
points.Add(new Vector3(x * ornt.x, 0, z * ornt.y));
print("dist" + Vector3.Distance(new Vector3(x, 0, z), Vector3.zero));
}
//visualy display the points
DisplayPoints();
}
void DisplayPoints ()
{
for (int i = 0; i < points.Count; i++)
{
GameObject dspl = GameObject.CreatePrimitive(PrimitiveType.Cube);
dspl.transform.position = points *;*
-
}*
- }*
I would realy apreciate any advice, fix or perhaps a better of doing this. and sory for the long post. Have a happy valentines day!