Search Unity

How does the Exporting of Parented Colliders work?

Discussion in 'Physics for ECS' started by Jawsarn, Mar 16, 2020.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    In the BuildPhysicsWorld the LocalToWorld is used for parented colliders. But in ExportPhysicsWorld this doesn't seem to be the case, it writes back to the transform only and doesn't have any LocalToWorld checks.

    Where does the computation from world back to local happen when exporting? It doesn't seem to fetch the Translation when building if it has the LocalToWorld?
     
  2. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    There is no such transformation.

    The BuildPhysicsWorld system can only use LocalToWorld for static bodies, precisely because it does not need to write back values (i.e. the simulation does not affect them).

    For dynamic bodies, there are currently no checks, but the assumption is that they are un-parented (which is why we do this during conversion) and we are both reading from world space and writing back to world space values. As such, if someone _does_ in fact have a dynamic body parented in a hierarchy, the visual result will not match what is actually going on in physics simulation.
     
    Jawsarn likes this.
  3. andreicfsteaua

    andreicfsteaua

    Joined:
    Nov 18, 2019
    Posts:
    36
    I encountered this problem my self, I want to make an RTS and have a formation entity with the units parented to this entity. I want the units to be dynamic but they won't behave as expected(they fall through the ground). What am I supposed to do? The units are instantiated using a prefab.
    Code (CSharp):
    1. for (int k = 0; k < formationsCount; k++)
    2.         {
    3.             Entity formationMovementPoint = commandBuffer.CreateEntity();
    4.             commandBuffer.AddComponent<Translation>(formationMovementPoint, new Translation { Value = new float3(k * (0.5f + xSpacing) * formationWidth - formationWidth * formationsCount, 0, 0) });
    5.             commandBuffer.AddComponent<LocalToWorld>(formationMovementPoint);
    6.             commandBuffer.AddComponent<Rotation>(formationMovementPoint);
    7.             commandBuffer.AddComponent<RotationEulerXYZ>(formationMovementPoint);
    8.             commandBuffer.AddComponent<FormationMovementPointTag>(formationMovementPoint);
    9.             commandBuffer.AddComponent<DeltaRotation>(formationMovementPoint, new DeltaRotation { value = 0.1f });
    10.             commandBuffer.AddComponent<TurningFactor>(formationMovementPoint, new TurningFactor { value = 1f });
    11.             commandBuffer.AddComponent<MovementData>(formationMovementPoint, new MovementData { speed = speed, target = new float3(k * (0.5f + xSpacing) * formationWidth - formationWidth * formationsCount, 0, 0) });
    12.             for (int i = 0; i < formationWidth; i++)
    13.             {
    14.                 for (int j = 0; j < formationHeight; j++)
    15.                 {
    16.                     Entity unitEntity = commandBuffer.Instantiate(unitPrefab);
    17.                     commandBuffer.AddComponent<UnitTag>(unitEntity);
    18.                     commandBuffer.AddComponent<LocalToParent>(unitEntity);
    19.                     commandBuffer.AddComponent<Parent>(unitEntity, new Parent { Value = formationMovementPoint });
    20.                     commandBuffer.SetComponent<Translation>(unitEntity, new Translation { Value = new float3(i * xSpacing, 0, j * zSpacing) });
    21.                 }
    22.             }
    23.         }
    Do i have to unparent them and store the units in a dynamic buffer and apply all changes to their transforms and rotations by myself? That would require me to change more systems.........
     
  4. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    @andreicfsteaua Hard from just reading the text you gave, but don't think you would want to have parenting in your case, but a target position for one single unit to walk towards. Think how you will transfer movement to be possibly used to animations etc from your hierarchy here, it would be better to deal with from a single unit entity. But I might misinterpret your game.