How do I make a rotatable procedural circle in 3d space?

I’m trying to make a plant that grows upward in different variations depending on variable changes within it’s script(s). How I’ve been running it so far is with a game object that starts at point zero, makes 8 vertices in a circle around it, which would be the base of the plant. Next, I would like to move the gameObject upward and rotate it some, then spawn 8 more vertices that will get connected to the first 8 to create the beginnings of a stem.

The problem I’m having, is that I can’t get the vertices to spawn in at a rotated angle along with the gameObject…they’re flat, on the gameObject origin with no rotation. I believe my problem is that my vertices aren’t being created on the gameObject’s x,y,z but world relative. How do I rotate the game object and then manifest these points onto th game object’s axis?

void Start () 
	{
                all of these points are Transforms
		point1 = getPoint(point1,360);
		point2 = getPoint(point2, 45);
		point3 = getPoint(point3, 90);
		point4 = getPoint(point4, 135);
		point5 = getPoint(point5, 180);
		point6 = getPoint(point6, 225);
		point7 = getPoint(point7, 270);
		point8 = getPoint(point8, 315);			
		
	}

Vector3 getPoint(Vector3 changePoint, int angle)
{
float myCos =   position.x +Mathf.Cos( angle * Mathf.Deg2Rad)*radius;
float mySin =   position.z +Mathf.Sin(angle * Mathf.Deg2Rad)*radius;	
				 
changePoint.position= new Vector3(myCos,0 , mySin);
return changePoint;
}

[22896-verticeissue.jpg|22896]

–

Added a response to your new drawing to the bottom of my Answer.

–

1 Answer

1

I’m confused some about what you are really asking. Plus I’m not sure where you are going with the points you generate. Build a mesh? Build a plant out of primitive objects? Anyway here is a bit of code that creates rings of spheres. Each ring is rotated by ‘offset’ from the previous ring. ‘divisions’ determines how many spheres are in each ring. These rings are built relative to the game object. They start at the game object and are built in the ‘up’ of the object. In addition, they are made children of the object the script is on, so you can rotate all the spheres as a unit by rotating the parent game object.

To use, create a new scene, create an empty game object. Position the empty game object at (0,-1.5,0), add a directional light to the scene (Game Object > Create Other > Directional Light), add the following script, and hit play:

using UnityEngine;
using System.Collections;

public class Circles : MonoBehaviour {

	private float offset = 3.0f;
	private float segHeight = 0.35f;
	private float radius = 1.25f;
	private float divisions = 16;

	void Start () 
	{
		float angle = 360.0f / divisions;

		for (int i = 0; i < 15; i++) {
			for (int j = 0; j < divisions; j++) {
				GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
				go.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
				Vector3 pos = GetPoint(j * angle + offset * i, segHeight * i);
				go.transform.position = transform.TransformPoint (pos);
				go.transform.parent = transform;
			}
		}
	}
	
	Vector3 GetPoint(float angle, float z)
	{
		float myCos =   Mathf.Cos( angle * Mathf.Deg2Rad)*radius;
		float mySin =   Mathf.Sin(angle * Mathf.Deg2Rad)*radius;    
		 
		return new Vector3(myCos,z , mySin);
	}
}

Dude! Thank you! That's all it was! I've been going crazy trying to figure this out. Thank you so much. Now that this is figured out, I should have a model of this thing up and running soon. I'll send you a link to it in here. I tried to hit the thumbs up over there on the side but it says I don't have a large enough reputation to tell you good job and thank you through a green thumb. Thank you so much for your help.

–

Rather than thumbs up, when your questions is answered, click on the checkmark. This closes the question out and you will see the icon on the question list as green.

–

Got it. Now I know. Thanks again.

–