- Home /
ECS set the translation to world position
I have the following hierarchy of game objects which will be converted to entities:
Parent
|- Child1
|- Child2
The parent has an AuthoringComponent
and all objects will be converted to the ECS.
In the entity component system, the parent will translate/rotate. On top of that, Child1 and 2 will have to be set to a world position fed from outside of the entity component system from a monobehaviour. My approach:
Entities.ForEach((ref ChildComponent childComponent , ref Translation translation, ref Rotation rotation, ref LocalToWorld localToWorld) =>
{
var worldPosition = GetWorldPositionForChild(childComponent.ChildType);
localToWorld.Value = new float4x4(rotation, worldPosition);
});
However, no matter the world position set to the children, they will always appear to be in (0, 0, 0) local space compared to the parent. I also tried setting the ref Translation
component to the world position or localToWorld.Position - translation.Value
to calculate the local space difference but that gave me even more bizarre outcomes.
How do I calculate the offset needed?