Members - Reputation: 104
Posted 25 September 2012 - 04:03 PM
http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/ - A really helpful series on Entity Systems
http://entity-systems.wikidot.com/ - The ES wiki
http://gamadu.com/artemis/ - An ES framework similar to the one I'm using now.
So if you have heard of them, my question is this:
How do you get complex behaviour out of an Entity using Systems and its Components alone? An example: say your Entity is a spaceship for all intents and purposes. Each spaceship might have a different weapon, and so fire bullets in a completely different way. How can you give it a data-only component that describes exactly how it fires bullets?
Or think of its AI (in the game dev sense), how can you describe how it moves and when it fires based solely on its components?
I'm not sure if there is a clean way to do it, but at the moment it's causing me significant trouble. I have like three git branches doing it different ways and I hate them all.
Members - Reputation: 1108
Posted 25 September 2012 - 05:22 PM
Honestly without much description of what type of projectiles you are having it is hard to describe a component and system that will match all your use cases will you be using simple raycast tests or physics simulated projectiles? Will there be ray guns? Or what? I don't know the limits of your technology or how it works.
A projectile for my game would be it's own entity which I would create from physics components and a projectile component. The projectile component would have stuff like initial velocity and who shot it and would notify it's creator when it hit something (probably with what it hit). So a 'firing component' would just be an entity link to create.
I always do AI in scripts which will access systems like path-finding and receive messages from the physics system when a collision occurs. So my script would just create the entity I wanted when it shot (after deciding to or receiving input (well after an animation maybe ).
Edited by CRYP7IK, 25 September 2012 - 05:26 PM.
Gold Coast Studio Manager, Lead Programmer and IT Admin at Valhalla Studios Bifrost.
Crossbones+ - Reputation: 5134
Posted 25 September 2012 - 06:07 PM
For more complex things, I attach scripts to the entity (via a Scripts component).They don't really keep the potential performance benefits of a component system (e.g. operating on all instances of particular data at once), but they also tend not to be as performance-critical anyway.
Members - Reputation: 277
Posted 25 September 2012 - 07:04 PM
- Components provide the data/properties/attributes and can provide behavior.
- Components register their properties with the parent entity so other components can access common data (eg. physics/render both need access to transform data).
- Sub-systems manage and update the components.
For the majority of things you will already have a bunch of sub-systems that are part of the core engine (physics, rendering, animation, etc) and so a lot of your components plug into these systems nicely.
For your spaceship/bullet example you could try tackle the problem in a more generic way. What makes up a bullet? In the most basic sense it has some kind of visual representation along with some physical properties. You could therefore create a bullet entity that is made from a couple of components:
- SpriteComponent or ModelComponent
The rendering components can be broken down even further but I find in most cases your components will generally map to an existing higher level sub-system, you just need to think in general terms of what actually makes up the object you're trying to create.
Edited by Shael, 25 September 2012 - 07:05 PM.
Members - Reputation: 104
Posted 26 September 2012 - 07:35 AM
Sorry I wasn't more clear about the projectiles: if it were only a single projectile there would be no problem, but it's a pattern of shots that I want to achieve. For example, spirals or rings of bullets being fired at once. So it's not not so much describing the projectile as describing how many, and in what formation, they are fired.
Is this something I should be using scripts for as well?
Members - Reputation: 470
Posted 26 September 2012 - 01:09 PM
Shooting is always going to be shooting, that is a behavior that you should implement in your code, deciding to shoot is something more dynamic that you may want to do through scripts.
As for the shooting pattern, its a matter of data, you can write as data a representation of the pattern, frequency, directions, speeds, projectile type. All this is data, not behavior, your behavior is shooting, which will receive this data and simply execute it, keeping track of time between shots and so on.
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
Crossbones+ - Reputation: 3389
Posted 26 September 2012 - 02:44 PM
Just a thought.
---(Old Blog, still has good info): 2dGameMaking
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)