Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Rotation at second prefab iteration

Discussion in 'World Building' started by Ambrose998800, Apr 27, 2019.

  1. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    28
    Hi there!

    I hope this post is in the right subforum. Anyway...

    I try to auto-create a labyrinth. Basicly it works fine, but I have a problem with the room alignement of the second (and any further) iterations.

    All the premade rooms are set up the same way in blender:
    LabyrinthConstructer_RoomSetup.png
    Note that all the ways out of a room are made by an marker (as child of the room) showing into the way out direction. The rooms way in is always the rooms pivot and in positive X direction.

    Now, I instantiate the first generation of rooms as a child of the way out marker and align it via code:
    Code (CSharp):
    1.                     NewRoom.transform.localPosition = Vector3.zero;
    2.                     NewRoom.transform.localRotation = Quaternion.identity;
    That works like a charm:
    LabyrinthConstructer_FirstIteration.png

    Then, one further iteration (setup the same way):
    LabyrinthConstructer_SecondIteration.png
    Note that the highlighted room is aligned to global-rotation zero instead of aligned to its parent rotation (the markers rotation).

    Why does it work the first time, but not the second time by the same code, but with just the "i" in the for-loop changed...?
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    596
    You should post the part of the code that does the layout/produces the problem.
     
  3. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    28
    There was no problem produced, just the result was wrong.
    It was a blender-Unity export/import twist-thing. I will never get used to that.

    My Maze-Creator is now running like a charm:

    CityCreator.png

    If someone has the same issue with blender-unity .fbx things, here is what I did for clean results:
    - Choose one object orientation for everything you create in blender (even child-objects; for me its X-Forward and Z-Up) and set it in the .fbx exporter.
    - Make sure to clear all objects scale and rotation in blender (ctrl+a in object-mode).
    - Disable Unitys 'Convert Units' at the imported file. Scale the objects down to 1, 1, 1 again.
    - Set all local rotations you need in Unitys scene-editor (they are turned to blenders X-Forward after import).
    - Now all childs (with transform.localRotation = Quaternion.identity) will have the correct orientation when added to another local child-object.

    Thanks a lot Flavelius, you're all time up to help! Cheers