How do I code one collision event for multiple enemies

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • I've got a question concerning multiple enemies colliding with a player character. The best way I can explain this is with an example. Let's say I have a platformer with two enemies:

    1) Thief (causes 2 damage on a player collision)

    2) Robber (causes 3 damage on a player collision)

    And my player is the Hero of the game. Now, let's say an instance of the Thief enemy collides with my Hero. I want to subtract two health from my Hero's health variable along with running a few other things on that collision event (i.e., have the Hero blink red, pause for a second, play a "grunt" noise, etc).

    I could do this with the On Collision event in Construct and code two separate events for each combination of Hero and enemy ("On Hero Collision with Thief" and "On Hero Collision with Robber") but is there a way for me to do this with one collision event--have some way to detect which enemy has collided with my Hero on a collision event and subtract the appropriate amount of damage from my Hero's health?

    At the moment, I can assign an instance variable to each enemy type and give it a value (Thief.damage = 2 and Robber.damage = 3) and on a collision event, call that variable when I'm subtracting health from my player (Current Hero.health - *.damage = new Hero.health)....but that would still require a unique collision event for each enemy type. How could I go about having multiple enemies, but not coding a separate collision/damage-Hero-health event for each enemy type and Hero combination?

    Sorry if this isn't clear, let me know if there is anything I could do to clear it up. Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah, okay, thank you. I didn't realize Families existed in Construct 2. I'm still somewhat of a beginner. I just found out they won't work for the free edition, but I'll be sure to use them if/when I buy the full edition. Thanks!!!

  • One thing you could do is make both the robber and thief the same object and just give them different stats (ie damage) and pin different sprites to them based on what they are.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)