How do I code one collision event for multiple enemies

Get help using Construct 2

Post » Sat Apr 30, 2016 1:23 am

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!
B
3
Posts: 2
Reputation: 179

Post » Sat Apr 30, 2016 1:53 am

Image
B
65
S
23
G
7
Posts: 1,504
Reputation: 10,894

Post » Sat Apr 30, 2016 2:01 am

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!!!
B
3
Posts: 2
Reputation: 179

Post » Sat Apr 30, 2016 4:10 am

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.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153


Return to How do I....?

Who is online

Users browsing this forum: ajcoppersmith, blue visionary and 5 guests