Component question
Posted: 2013-04-18, 16:46
Hi, Carsten.
I'm curious about the way you plan to implement certain game mechanics via components. For instance, a pickable item, let's say a key. I imagine the game object (GO) will have components:
I'm also thinking about various ways you can do broadcasting events. One that comes first is that when a component wants to broadcast a message, it tells the game object (GO) and then GO tells other components that listen for the particular event. So on init, components that need to listen for certain events do register themselves as listeners in GO. Say, a collision component calls an "onTouch" event, coupled with a (Lua) table filled with data such as who the toucher is (most likely the player), point of touch, etc., and then GO looks through its list of listeners and send the data table to all who listen for "onTouch". The listener simply checks the table and behaves based on it.
Another topic is the Transform component. In Unity, EVERY GO has the Transform comp by default. It implements position, rotation, scale and all the necessary functions to modify these values. To me, it seems like this could be directly implemented in GO class itself, since every single GO instance has the Transform comp anyway.
What's your take on all these points?
I'm curious about the way you plan to implement certain game mechanics via components. For instance, a pickable item, let's say a key. I imagine the game object (GO) will have components:
- Model - 3D model representing the key.
- Collision - component defining the collision for the GO. Perhaps this will broadcast "onTouch" event?
- Pickable - basic component implementing functions regarding what happens when the GO is touched. Or a component derived from this basic component that defines what exactly happens - in our case, just add a key to player's inventory.
- Light - casting light to make the item more striking.
- Wobble - component making the GO wobble in a sine manner (or whatever). Heretic and Hexen have items like this - looks nice.
I'm also thinking about various ways you can do broadcasting events. One that comes first is that when a component wants to broadcast a message, it tells the game object (GO) and then GO tells other components that listen for the particular event. So on init, components that need to listen for certain events do register themselves as listeners in GO. Say, a collision component calls an "onTouch" event, coupled with a (Lua) table filled with data such as who the toucher is (most likely the player), point of touch, etc., and then GO looks through its list of listeners and send the data table to all who listen for "onTouch". The listener simply checks the table and behaves based on it.
Another topic is the Transform component. In Unity, EVERY GO has the Transform comp by default. It implements position, rotation, scale and all the necessary functions to modify these values. To me, it seems like this could be directly implemented in GO class itself, since every single GO instance has the Transform comp anyway.
What's your take on all these points?