Accessing ChildOf entity

Hello,

Related to the turrent animation topic, how do you manipulate the ChildOf entity.

If you need to set the turrent rotation relative to the tank rotation, you probably have a TurretPositionSystem with a set requiring a Position component, a ChildOf component and probably a Turret component (as a tag, are you doing this?). Now browsing the examples i haven’t seen you used more than one set for one system (sorry for calling it like that), so do you get the parent entity position (tank) directly from the entity manager or you use two different sets from within the same system?

I’d probably use two different sets in the same system. Both the turret and the tank might have regular Position components but the turret would also have a ChildOf component that denotes that it should be attached to the tank and therefore its position is relative to the tank’s.

So my model system in that case would probably have an entity set of (Position, ModelType, whatever) and one of (Position, ChildOf, ModelType, whatever)

The turret will show up in both but that’s easy enough to disambiguate. In fact, the regular Position, ModelType updates can update the turret, too. You only need the ChildOf to switch the parent from the main root to the tank. So you could even just watch (ChildOf and ModelType) but I think Position adds some nice filtering if you ever use ChildOf for other types of children also… and it does no harm to select it. (It also means that if you remove the Position component it will automatically disappear from both sets.)