Parent/Child getting world positions


How do you guys handle parent/child relations in the ecs world.
The actual case is the turret of a tank. The problem i am facing is that for rotating the turret to the target vector i need to know the world translation of the turret. Up to this point i have never needed any information from a “child” that changes when the parent changes, so i currently do not even have a scenegraph on the server side.

As far i see i have the option to do the local to world conversation myself, or add the full graph.

I am just wondering if i am missing a third solution, or in general if there is a better way.

My entity system is not an ECS, but it uses similar concepts. In mine, relationships like this one wouldn’t typically be separate entities, but rather the turret would be a distinct “part” of the tank and parts have a local transform that’s combined with the transform of any parent parts up to the entity root (just like jME’s scenegraph). There’s no accumulation or caching of transforms now, and I’d like to avoid that if possible.

In your shoes I’d probably just do the local → world calculation as needed.

I prefer the separate entity, mainly because mutiple turrets per tank, different targets for each turret on a single tank, turrets mounted on anything, works out of the box.

Maybe your part systems works the same way. idk

You should probably do this without the scene graph. The scene graph is a huge and dependency-ridden chunk of code just to calculate parent-relative positioning.

…when I need to calculate the position of a child, I just do it. It’s one or two lines of math. (Edit: in fact, the SimEthereal stack is doing this automatically all the time anyway.)

Do you need to somehow do this continuously? That may indicate a different sort of design solution.

Hm, well the turrets need to get aligned to the target each tick.
The turrets world position would have to be recalculated each tick if the parent has changed translation.

So i would say conditionally continuously.

Is the like AI making a calculation or you have some system that’s only job is to point the turrets at their targets?

It would be a single purpose system rotating the turrets based on some contraints. (max angular speed, max angle)