which system handles stuff?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • which system handles stuff?

      Gday,

      I have a health system and a collision system.
      The health system which doesn't nothing at the moment but listen for 'modifyHealth' events.

      My question is, does it make more sense for the health system to listen for collision events and handle them, or for my collision handling to send out 'modifyHealth' events where appropriate?

      I am thinking maybe the former because the latter implies that the collision knows about the health system...

      What do people think?
    • Thanks Trinak for your reply.

      Yes, there is only one health system that handles all entity health components. But I think I composed my question poorly. I'll try again:

      I have the following options:

      The health system listens for collision events then updates health components?
      or
      The collision handling sends out modifyHealth events where appropriate that the health system will listen for?

      I am trying to avoid a large switch statement. If my health system listens for collisions then when it receives one it needs to figure out which entities in the collision receive what damage. I suppose I could handle that in the components but then i need to sub class health component for every entity that handles it differently. Or do I?
      But I guess the code has to go somewhere...

      The post was edited 1 time, last by quin ().

    • Generally something like health would be contained in a component on the actor itself, probably in a statistics component, along with things like; stamina, speed, etc.

      How you link the event that 2 objects collide to a change in your health varies:

      - Register a callback, this is almost always something that physics systems implement, usually having 'collision types' that you may have set on colliders. If you are using your own collision system, you could take a similar approach and register callbacks for when actors collide.
      - You can also use the event system to send an event when actors are colliding, this will definitely have more overhead than the previous approach.

      There are other ways for sure, but I would make these key points again.

      - Health should remain the same from actor to actor in a central 'statistic' component.
      - Collision should not have a concept of what health is, coupling the health system into the collision system is not ideal
      - Possibly a 3rd component (or even a script) would handle the reception of collisions, and would modify the health component accordingly.

      Here is a quick example using Lua

      Source Code

      1. -- 'this' represents the actor the script is on
      2. -- otherActor is the actor being collided with
      3. function OnCollisionEnter(otherActor)
      4. -- Tags are a nice feature to have for your actors
      5. if(otherActor.GetTag() == "Player")
      6. then
      7. -- Each actor has a statistics component, with 'Health' and 'Damage' statistics, these would map to number values
      8. local statisticsComp = otherActor.Statistics;
      9. local nHealth = statisticsComp.GetStatistic("Health");
      10. nHealth = nHealth - this.Statistics.GetStatistic("Damage");
      11. statisticsComp.SetStatistic("Health", nHealth);
      12. end;
      13. end;
      Display All
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • Hey, thanks! I see.
      Yes, I have implemented my own physics including collision detection.

      You are saying that you would have a method inside your physics/collision component for the physics to callback to.

      I see here that the callback function will need a switch statement for each possible collision type.

      Would you do other functionality inside this callback as well? such as requesting a new animation and requesting particle effects etc.?

      Cheers.

      The post was edited 1 time, last by quin ().

    • The physics/collision component would not contain any game specific code, you would have another component for that stuff, the system components like physics and collision should work for almost any game you plan to make, where a 'Goblin' component would have its own logic strictly for goblins.

      You wouldn't need a switch statement at all, instead you would map the collision type to a function callback, what I usually do is have a collision type registry which gives a unique integer to whatever string you pass in, so if you register 'Missile' first, it would get 0, than if you register 'Car' you would get 1, and so on. Depending on how you want to do things, you could have 1 callback that ALWAYS handles 1 set of collision types, ie. Missile-to-Car, or you could have callbacks that would handle each type separately. The first method would likely be more performant. So rather have one large callback with a switch statement that handles all of your collision types, you would have one callback per type.

      I would say a good run down on how a collision would turn into game feedback would be.

      - Create a 'Missile' actor and a 'Car' actor, both would register with their own respective collision types
      - Callbacks would be registered with the collision system, each type would get a callback
      - The callback would determine which actors are which in order to utilize them (if using the dual actor callback method)
      - The appropriate actions would be taken to make the desired feedback

      Source Code

      1. function CollisionCallback(actorA, actorB)
      2. -- Find out who is who
      3. local missile = (actorA:GetTag() == "Missile") and actorA or actorB;
      4. local car = (missile == actorB) and actorA or actorB;
      5. -- missile.Missile is a component specifically made for Missiles
      6. local nDamage = missile.Statistics:GetStatistic("Damage");
      7. missile.Missile.Explode(); -- This will likely spawn a process for a kill timer, as well as create some explosion effects
      8. local nHealth = car.Statistics:GetStatistic("Health") - nDamage;
      9. car.Statistics:SetStatistic("Health", nHealth);
      10. if(nHealth <= 0)
      11. then
      12. car.Car:Explode(); -- This will do roughly the same thing as the Missile.Explode();
      13. end;
      14. end;
      Display All


      These are really simple examples, but it should help you.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Thanks :D
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Back for more help.
      I browsed the forum (couldn't search) and couldn't find where this question may have been answered previously. So sorry if it has.

      Basically, I need to render a health bar and to scale it according to the health.

      So i have my 'goblin' with a render component. This component has a method that creates its scenenode.
      Is it in this method that I need to include the health bar scenenode as a child?
      I need a render component for the health bar with render data and so I can update its scale based on the health values.
      I want to keep it generic as possible because I am not sure yet what I will be adding health bar's to, and an entity may include health but not necessarily render a health bar. Perhaps I just need a second rendercomponent for the entity...

      I am not sure how to handle this. Any tips will be greatly appreciated.

      The post was edited 2 times, last by quin ().