I would like to make fractal tree in Unity3d, omitting branch angles and lengths, just to instantiate cubes as a tree, like 2,4,8,16… i look for solution all day and i figure it could take me days yet? Should i use an array to store and recall a list of coordinates that each new branch should be at? would it contain 2 or 16 values?
Here is an interactive JS code for trees:
http://www.processing.org/learning/topics/tree.html
It uses the following code, please bypass the canvas, rotations, stalk length, i’d be so happy to just have a tree like in the image.
branch(120);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}
here is my funny attempt thus far:
var bullet : Transform;
private var rot : Quaternion;
function Start()
{
for (var j : float = 0; j<10; j++)
{
for (var i : float = 0; i<10; i++)
{
rot.eulerAngles = Vector3(0,10,0);//Rotation to use with instatiation
var InstantiateObject = Instantiate(bullet, Vector3(Mathf.Sin(i*432)*i*j,j*5,Mathf.Cos(i*4375)*i*j), rot);//call clones
InstantiateObject.localScale += Vector3(25-j*2,22-j*2,22-j*2);//resize clones
}
}
}