Sign in to follow this  
PhilLiu

Entity Component Model Collisions

Recommended Posts

Hello,

When using the Entity Component Model, what is generally accepted to be the best method for collision checks?

Does the Collision Component simply listen for collisions or does it actually check for collisions?

Share this post


Link to post
Share on other sites
How about,

1, Entity provides the collision data (shape, etc), maybe via a component (collision data component),
2, A sub system, processes all collision data in each frame.
3, If any collision occurs, the sub system just emits an event.
4, Any interesting component subscribes to the events. An AI component of an enemy may want to know when the hero hits the ground, etc.

Share this post


Link to post
Share on other sites
wqking,

Your proposal is similar to the architecture I decided to use last night. After doing some research I found this:

[url="http://www.gamadu.com/artemis/"]http://www.gamadu.com/artemis/[/url]

I really like the idea of every bit of ingame logic being a 'system'. However, I was still having issues figuring out where to generate events.

I guess having a global collision detection system would be the best way. Then, I would have to use a listener structure for collision events, like you sugguested.

Share this post


Link to post
Share on other sites
An alternative of listener is that, register a component which is to response collision, such like a CollisionSolverComponent.
When collision occurs, the sub system just try to find if there is CollisionSolverComponent in the entity, if there is one, call special function on it.

This method is more coupled, but may (or may not) be more efficient than event dispatch.

Of course CollisionSolverComponent can listen to the events, then no need of the component look up.

Share this post


Link to post
Share on other sites
OK, for the purposes of performance, I don't believe it's efficient to have each object have its own subsystem to check for collisions. This is because the world object list must be accessed multiple times and, due to the limitations of Java, I must create an array version of my list in order to use it and modify the object at the same time. Thus, I think the most elegant solution is probably a CollisionHandlerComponent like you suggested, and stick the CollisionGeneratorComponent into the WorldEntity.

Share this post


Link to post
Share on other sites
"each object have its own subsystem" ?

I think you misunderstand about sub system.
A sub system is NOT for any single object, it's for the whole sub behavior, which may include a lot of entities or components.

For example, a game may have several sub systems, rendering sub system, resource management SS, physics and collision SS, etc.
If an entity needs to render itself, just provide data to rendering sub system.

So an entity, or an object, doesn't have any sub system. Sub system is in quite global and top level.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this