Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Complex Components in Entity Systems

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 PanicBox   Members   


Posted 25 September 2012 - 04:03 PM

Alright, if you haven't heard of Entity Systems before, here are a few links that got me started:

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.

#2 CRYP7IK   Members   


Posted 25 September 2012 - 05:22 PM

It might be a good idea to tell us exactly what trouble you are having because, to me, from your description these are not complex components.

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 Posted Image).

Edited by CRYP7IK, 25 September 2012 - 05:26 PM.

To accomplish great things we must first dream, then visualize, then plan...believe... act! - Alfred A. Montapert
C# Programmer and Unity Developer at Well Placed Cactus.

#3 phil_t   Members   


Posted 25 September 2012 - 06:07 PM

The bullet example I think could be addressed using components (depending on how "differently" you want bullets to fire).

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.

#4 Shael   Members   


Posted 25 September 2012 - 07:04 PM

There are a number of ways to implement a component based entity system. The system I have been working on works a bit like this:
  • 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:
  • TransformComponent
  • PhysicsCapsuleComponent
  • SpriteComponent or ModelComponent
For the above, the TransformComponent is there to provide the world/local transform that the physics/render systems can read/write too. The PhysicsCapsuleComponent is managed by the physics sub-system and it's attributes define the physical properties (velocity, acceleration, friction, collision mesh, etc) which the physics sub-system uses to simulate the object. The SpriteComponent or ModelComponent provides the visual representation and it is managed by the rendering sub-system.

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.

#5 PanicBox   Members   


Posted 26 September 2012 - 07:35 AM

The Script components make a lot of sense and are a great idea.

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?

#6 NEXUSKill   Members   


Posted 26 September 2012 - 01:09 PM

There is nothing wrong with the components of an entity having some behavior of their own, don't make complex logic and math computations on script, they tend to get expensive since they have to be interpreted, the best us of scripts is to connect different behaviors in a dynamic way. Don't overuse scripts.
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.
Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

#7 BeerNutts   Members   


Posted 26 September 2012 - 02:44 PM

I would look at it this way. Your ship might have a Weaponry component, which holds the current weapons they can shoot (and possibly which one is active, if you can switch between them), as well as if its time to fire (set by AI System, or player's input system). In your Weapon system, it would create an entity based on the current firing weapon name. The entity could be built from loading an xml file (for that weapon's name) that describes the weapon's bullet's components (image, velocity, damage, number of pellets (if it spreads) etc.). If it's a special bullet, the Weapons system should know how to handle it

Just a thought.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.