Search Unity

Get the absolute position of a child entity

Discussion in 'Entity Component System' started by learc83, Sep 16, 2019.

  1. learc83

    learc83

    Joined:
    Feb 28, 2018
    Posts:
    41
    The translation components of child entities appear to behave as if they are relative to the parents position, which makes sense.

    But how do I get the absolute position of a child entity?

    In this case I need to move another unrelated entity to the child. Is there a way to do this that doesn't involve finding the parent's position and adding the child's position to it?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    LocalToWorld.position
     
    learc83 likes this.
  3. zanius

    zanius

    Joined:
    Feb 5, 2018
    Posts:
    24
    I had this exact problem and LocalToWorld.position was not giving me the correct value. It turns out the system that operates on LocalToWorld components was updating them after my system needed the value. LocalToWorld.position is the relative position until it's operated on by it's system. (Thanks to discord user psuong for figuring this out)
     
    learc83 likes this.