Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED] 2D positioning prefab with multi-children

Discussion in '2D' started by camboui, Aug 6, 2015.

  1. camboui

    camboui

    Joined:
    Jul 8, 2015
    Posts:
    6
    Hi,

    I'm currently trying to create an game based on infinity plateform ascension. To do it, I use prefabs with multi-children.
    On each of these prefabs, i placed 2 points (Top/Bottom).
    I want that the bottom of the next prefab to be on the top of the previous one.

    I thaught i could use the prefab center to calculate the right position.
    But when i Instantiate it, it doesn't fit. In fact, i understood that the transform.position of the prefab is not the middle of the prefab. ( Like on this picture )

    Is there a way to set the prefabs transform position at the right place ?
    Or have you got any better idea to perform this ?

    Thanks,
    Have a nice day !
     

    Attached Files:

  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Did you select only the parent object, or did you select its children, too? The translation widget should be exactly where transform.position is.
     
  3. camboui

    camboui

    Joined:
    Jul 8, 2015
    Posts:
    6
    Hi, thanks for answer,

    Yes, i selected everything. Look these pictures. According to the selections tools. They all give me the center of the prefab. Which is actually nothing.
    The last tool on the right shows me the real prefab transform.position because when i move the position in C#, this point is taken as transform.position.

    I found some kind of stupid fix :
    - create an empty GameObject
    - keep its position in mind
    - selected all children of the prefab and move them to the empty gameobject position
    - attach them to this empty gameobject.
    - It's the new prefab with the good transform.position

    Any idea of why it's not automatic ?

    Anyway i found the solution, quite simple. Don't know why i was stucked for one day. I just had to calculate the distance between the prefab transform.position and my bottom point and substract it to prefab transform.position.
     

    Attached Files:

  4. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    You should have selected only the parent.

    Glad you found the solution for your positioning problem :)
     
  5. camboui

    camboui

    Joined:
    Jul 8, 2015
    Posts:
    6
    Sorry, i misunderstood, i had selected only the parent. ( proof : if i had selected children the tool on the right would show a box)

    Thanks, for support, seems that you're always the first on topics ;)
     
  6. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Hmm, but if you had selected the parent only, then it would be quite odd if the translation widget wouldn't be at the same position transform.position gave you.
     
  7. camboui

    camboui

    Joined:
    Jul 8, 2015
    Posts:
    6
    Yes, but for a moment I was sure that i would need the center of the prefab