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. Dismiss Notice

Question ECS - Setting localToWorld doesn't update child entities positions.

Discussion in 'Entity Component System' started by Yoconn, Feb 2, 2023.

  1. Yoconn

    Yoconn

    Joined:
    Jan 12, 2015
    Posts:
    8
    How are you supposed to move a parent entity and have the child entities 'follow'?

    I've tried googling this but... I might be using the wrong terminology or something.

    I'm working off the Boids example and this is what I'm currently doing.

    Code (CSharp):
    1.                
    2. localToWorld.Value = float4x4.TRS(
    3.     new float3(localToWorld.Position + (nextHeading * MoveDistance)),
    4.     quaternion.LookRotationSafe(nextHeading, math.up()),
    5.     new float3(1.0f, 1.0f, 1.0f));
    6.  
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    791
    Yoconn and Anthiese like this.
  3. Yoconn

    Yoconn

    Joined:
    Jan 12, 2015
    Posts:
    8
  4. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    791
    Yes
     
  5. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    But how do you change the non-uniform scale if you shouldn't use localToWorld?

    ah, like this: https://forum.unity.com/threads/how-to-scale-a-entity-in-a-non-uniform-way.1411515/
    magical hidden by default component, got it.

    (the docs are very unclear what it is, "you may use a PostTransformScale (float3x3). This will be applied in the following manner: LocalToWorld = WorldTransform.ToMatrix() * PostTransformScale", had to search around a lot for usage and context; it didn't even mention it's a component or part of a component)
     
    Last edited: Mar 26, 2023
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    layker90524 likes this.