- Home /

# Help with L System Rotations

Hello I am having trouble getting a Hilbert curve to appear using the following L System:

**X:**"^ / X F ^ / X F X - F ^ / / X F X & F + / / X F X - F / X - /"**Initial String:**X**Angle:**90

The way I am calculating the angles is as follows

```
if (character == 'F')
{
Vector3 old_pos = turtle.transform.position;
GameObject new_point = Instantiate(point);
turtle.transform.position += line_length * turtle.transform.up;
new_point.transform.rotation = turtle.transform.rotation;
Vector3 pos = turtle.transform.position;
pos[0] += line_length;
new_point.transform.position = pos;
new_point.transform.localScale = new Vector3(starting_width, line_length, starting_width);
//new_point.transform.parent = turtle.transform;
Debug.DrawLine(old_pos,turtle.transform.position, colors[i%7], 5000f);
}
else if (character == 'f')
{
turtle.transform.position += line_length * turtle.transform.up;
}
else if (character == 'w')
{
starting_width *= width_ratio;
}
//Pitch down(&) and up(^) by delta
else if (character == '&')
{
turtle.transform.Rotate(Vector3.right * delta);
}
else if (character == '^')
{
turtle.transform.Rotate(Vector3.left * delta);
}
//roll right(/) and left(*) by delta
else if (character == '/')
{
turtle.transform.Rotate(Vector3.down * delta);
}
else if (character == '*')
{
turtle.transform.Rotate(Vector3.up * delta);
}
```

This system works with the following L System and produces the desired result

**A:**"[&FFFA] //// [&FFFA] //// [&FFFA]"**Initial String:**FFFA**Angle:**90

However when attempting to make a Hilbert curve and other L Systems the results are not as expected

What would be the correct way to go about coding these rotations in Unity described on page 3 in the following PDF: https://www.bioquest.org/products/files/13157_Real-time%203D%20Plant%20Structure%20Modeling%20by%20L-System.pdf

(I have tried writing out the rotation matrices but it didn't solve my problem. Let me know if any other information is required)

**Answer** by Bunny83
·
Dec 25, 2020 at 03:47 PM

It seems that your used L system rule is faulty. It looks very similar to the one mentioned over here but you don't have the proper counter rotations at some places. To quote from the SO answer:

```
lsystem Hilbert3D {
set iterations = 3;
set symbols axiom = X;
interpret F as DrawForward(10);
interpret + as Yaw(90);
interpret - as Yaw(-90);
interpret ^ as Pitch(90);
interpret & as Pitch(-90);
interpret > as Roll(90);
interpret < as Roll(-90);
rewrite X to ^ < X F ^ < X F X - F ^ > > X F X & F + > > X F X - F > X - >;
}
```

If you compare it to your rule, you always use a "/" where in this rule there is either a `<`

or `>`

. So you're rotating in the wrong direction.

I haven't tried this 3d hilbert curve construction rule.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.