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

Plane transform bug or feature ?

Discussion in '2D' started by jquery, May 4, 2019.

  1. jquery

    jquery

    Joined:
    Jul 12, 2014
    Posts:
    10
    I have a standard simple plane on scene (Master Plane) Position : 0, 0, 0 Rotation : -90, 0, 0 Scale 2, 2, 2
    and I want to create prefab of smaller planes which must be child of master plane.

    I created other plane Position 0,1,0, Rotation 0,0,0 Scale 0.5, 0.5, 0,5 and drag it to asset folder to create a prefab.

    When I drag the prefab to Hierarchy tree as child of Master Plane it is rendered correctly and visible.
    Untitled.png
    Child plane has Position : 0,1,0 Rotation 0,0,0 Scale 0.5, 0.5, 0.5
    Child plane rotated with parent and keep own local Rotation 0,0,0

    When I create it in code ( script attached to Master Plane) as
    var plane = Instantiate(PlanePrefab, new Vector3(x, 0, y), Quaternion.identity, this.transform);

    It's created with not correct child local rotation changed to Rotation 90, 0, 0 looks like rotation applied from Master Plane + Child Local and it's become not visible.

    How I can get the same result with Prefab in code as I get in editor ?
     
    Last edited: May 4, 2019
  2. RockyWallbanger

    RockyWallbanger

    Joined:
    Mar 16, 2014
    Posts:
    85
    Replace Quaternion.identity with
    Code (CSharp):
    1. Quaternion.Euler (-90f, 0f, 0f)
    From the docs
    That means that your object has to offset the child's rotation to get it back to world space 0. If you create a plane that's not a child of the master plane, and set the transform to those same values, you'll get behavior similar to your instantiation code.