Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotations give predicted shape when applied separately but warped shape when combined (Pic)

Discussion in 'General Graphics' started by WilkinsMicawber, Feb 15, 2016.

  1. WilkinsMicawber

    WilkinsMicawber

    Joined:
    Jan 22, 2016
    Posts:
    27
    I create hundreds of primitive cubes positioned along the top of another cube so that they are side by side. I then apply outward rotations and upward rotations to each. The upward and outward rotations look exactly as expected applied separately but result in a warped shape when combined. The code is:

    //cube[] is an array of the primitive cubes

    vertical:
    for (int x = 0; x++; x < cube.count)
    {
    cube[x].transform.RotateAround(cube[x].transform.position - new Vector3(cube[x].transform.localScale.x / 2f, cube[x].transform.localScale.y / 2f, transform.localScale.z / 2f), new Vector3(0, 0, 1), 45f);
    }

    horizontal:
    for (int x = 0; x++; x < cube.count)
    {
    cube[x].transform.RotateAround(cube[x].transform.position - new Vector3(cube[x].transform.localScale.x / 2f, 0, 0), new Vector3(0, 1f, 0), drawAngle);
    drawAngle -= .10f;
    }
    grahics1.png

    Any idea what is happening?