Component Architecture, Collisions and Messaging
Posted: Fri Apr 08, 2011 12:57 am
Hello,
This is more of a general game implementation question than a purely physics related question, but it is physics based so I thought I'd still post it here, sorry if its outside the realm of this forum.
First some background context:
I'm currently trying to implement a component based architecture for my game. I have a container class to store components that make up that object, and component classes to implement various aspects of that object. ie. a "player" container could container the following components: rendering, playerinput, physics, etc.
My physics component contains an Entity and handles it being added/removed to the Space. This component relays information such as position and rotation to other components who listen for changes in such information. The components is also aware of the container it belongs to.
Now, my current dilemma. I wish to create a physics component to act as a weapon, so that I can tell when the weapon's Entity has hit an enemy's physics component's Entity and then send a message from the weapon to the Enemy container class saying "take this much damage, blah blah blah".
Entity A can tell that it collided with Entity B.
Entity A can tell PhysicsComponent A (which it belongs to) that it has collided with Entity B.
So PhysicsComponent A can know it hit Entity B
and obviously vice-versa,
Entity B can tell that it collided with Entity A.
Entity B can tell PhysicsComponent B (which it belongs to) that it has collided with Entity A.
So PhysicsComponent B can know it hit Entity A
But how can PhysicsComponent A know that it collided with PhysicsComponent B? So that I can (for example) send a message from PhysicsComponent A to PhysicsComponentB's container class.
I hope this makes sense, if its needs further clarification please just ask. I appreciate your time for reading this and any possible pieces of advice you can offer.
Kind Regards,
Kataan
PS. I guess I could just cycle through each container and check if its physics component's Entity matches the one I collided with, but that seems like a horrible way to do it and I'd rather not resort to that.
This is more of a general game implementation question than a purely physics related question, but it is physics based so I thought I'd still post it here, sorry if its outside the realm of this forum.
First some background context:
I'm currently trying to implement a component based architecture for my game. I have a container class to store components that make up that object, and component classes to implement various aspects of that object. ie. a "player" container could container the following components: rendering, playerinput, physics, etc.
My physics component contains an Entity and handles it being added/removed to the Space. This component relays information such as position and rotation to other components who listen for changes in such information. The components is also aware of the container it belongs to.
Now, my current dilemma. I wish to create a physics component to act as a weapon, so that I can tell when the weapon's Entity has hit an enemy's physics component's Entity and then send a message from the weapon to the Enemy container class saying "take this much damage, blah blah blah".
Entity A can tell that it collided with Entity B.
Entity A can tell PhysicsComponent A (which it belongs to) that it has collided with Entity B.
So PhysicsComponent A can know it hit Entity B
and obviously vice-versa,
Entity B can tell that it collided with Entity A.
Entity B can tell PhysicsComponent B (which it belongs to) that it has collided with Entity A.
So PhysicsComponent B can know it hit Entity A
But how can PhysicsComponent A know that it collided with PhysicsComponent B? So that I can (for example) send a message from PhysicsComponent A to PhysicsComponentB's container class.
I hope this makes sense, if its needs further clarification please just ask. I appreciate your time for reading this and any possible pieces of advice you can offer.
Kind Regards,
Kataan
PS. I guess I could just cycle through each container and check if its physics component's Entity matches the one I collided with, but that seems like a horrible way to do it and I'd rather not resort to that.