Adding sub-entities to existing entities. Should it be done in the Entity and Component classes?
Posted
by
Coyote
on Game Development
See other posts from Game Development
or by Coyote
Published on 2012-09-11T08:57:25Z
Indexed on
2012/09/11
9:51 UTC
Read the original article
Hit count: 325
I'm in a situation where a player can be given the control of small parts of an entity (i.e. Left missile battery). Therefore I started implementing sub entities as follow.
Entities are Objects with 3 arrays:
- pointers to components
- pointers to sub entities
- communication subscribers (temporary implementation)
Now when an entity is built it has a few components as you might expect and also I can attach sub entities which are handled with some dedicated code in the Entity and Component classes.
I noticed sub entities are sharing data in 3 parts:
- position: the sub entities are using the parent's position and their own as an offset.
- scrips: sub entities are draining ammo and energy from the parent.
- physics: sub entities add weight to the parent
I made this to quickly go forward, but as I'm slowly fixing current implementations I wonder if this wasn't a mistake.
Is my current implementation something commonly done? Will this implementation put me in a corner?
I thought it might be a better thing to create some sort of SubEntityComponent where sub entities are attached and handled.
But before changing anything I wanted to seek the community's wisdom.
© Game Development or respective owner