Lose 1 Health per Enemy = (For Each?)

0 favourites
From the Asset Store
Per Pixel Destruction like in "Worms" (perfect performance, no third party plugins)
  • Hey All,

    As I'm testing my current early state of my game I found out a bug and I'm not sure how to fix it.

    I attached a GIF so you can visualize how it looks, maybe it will help.

    Current state is:

    When enemy collide with the player, he loses 1 HP which is HALF a heart. 6 HP = 3 Hearts, so far so good right?

    On every HIT, the Player changes to Invincible for few seconds (while flashing).

    But I noticed this bug when I JUMP on 2 enemies at once the Player loses 2 HP instead of 1 (Full Heart).

    Since I'm still new to Construct 3 and learning programing with it as I go, I didn't use "FOR EACH" but I'm guessing it's something I should use to solve it? or maybe I'm wrong and it's something else.

    Can you please suggest me a solution so I can test?

    Thanks ahead!

    i.imgur.com/9lXkVSP.gif [/img]

  • I believe you need to use the "Trigger Once While True" condition. That way, instead of both enemies hitting you, only one will. Is that what you are looking for?

  • Thanks for the reply, My current code have this (image attached) trigger at once but it didn't solve the issue what made me to post this thread.

    I'm guessing I'm doing something wrong with the order maybe?

    I did play around with the order but... it didn't solve the issue.

    I thought it's because of the enemies are same instance or something but I just spawn 3 of them with the code instead of duplicate them manually on the stage.

    i.imgur.com/pnbHT3m.png [/img]

  • Try using a variable to detect when you are no longer touching the enemy and condition to check against it: https://www.dropbox.com/s/egaxp71n1snhbu6/enemyFirstCollison.c3p?dl=0

  • Thanks that's an interesting solution! I'll probably use it if there is no other solution.

    The thing is that I already have so many variables and I will add more and more both variables and enemies.

    So I wonder if there are other ways to do this without extra variables?

    I know it sounds weird, maybe it's a Create Object v.s. Spawn Object issue? I'm not sure.

    Any other solutions will be very interesting to see as I'm still learning.

  • I found out that it's a bit more complex than what I imagine.

    When I attack 1 enemy (2 hits = destroy for quick test) it dies, the rest keep moving around = GOOD!

    But... when I collide with 1 enemy, all enemies stops, change direction, keep walking (calls a simple function I made).

    So I have 2 issues now, and it's good to solve them before I'll add more enemies to the game to understand how to deal with it later, that's where I need your help.

    1# = As I posted originally, when the Player jumps to test collision with 2 enemies instead of hit once, both will damage at once = BAD (I need only one enemey to hit). gave a solution but I'm not sure if it's related to the 2nd Issue so I didn't use it yet.

    2# = I just described above (collision with 1 enemy affect ALL enemies).

    Are these 2 issues related and can be solved in the same condition, I'm a bit confused.

    I did try to use "FOR EACH" which I probably use totally wrong but it sounds like it could help...

    Dear dop2000 I bet you can solve this easily, you already helped me and many others so much!

    Can you please have a look on this post and share your advice / solution, example or visual image of how it's done will be very helpful.

    My wrong use of "FOR EACH" I just tried my luck since I don't know how to use it after reading about it.

    i.imgur.com/FueiQx3.png [/img]

    Example of the 2 issues mentioned above:

    i.imgur.com/9lXkVSP.gif [/img]

    Thanks ahead to anyone who can help! :)

  • Event

    object Player on collision with Enemy

    sub event

    for each enemy

    action do stuff: subtract player health and or set enemy parameters

    The subevent will loop through the enemies involved with the collision

  • Thank you lennaert, your explanation is great for a newbie like me to start understand how "FOR EACH" supposed to work!

    I tried to follow your steps, but there is no difference. both issues are still the same as I described above.

    Can you see where I did the mistake on the image I attached? maybe the order is wrong?

    Thanks ahead!

    i.imgur.com/Ad2iss2.png [/img]

  • Yep.

    The way you currently use the function it looses the reference to which gooe the action should be applied.

    Solution:

    Pass Gooie.UID as paramter when calling the function

    And in the function itself use Pick by unique ID ( function.param(0) ) to get the reference back.

  • Thanks for the quick reply!

    I lost you now, but I REMOVED the function since you said this is the issue, I got rid of it for testing.

    And both issues are still there, even when there are no functions at all.

    So... do I make it on the wrong order?

    i.imgur.com/i7U2tch.png [/img]

  • here is an example in its most basic form

    test

  • here is an example in its most basic form

    test

    Thank you for the example file!

    I don't see why it's not working on my code, maybe because there are more things like animations and stuff I even tried to look if I made any extra conditions that may clash, but nothing else.

    Even when I placed the enemies manually on the stage it's affecting all of them instead of each instance separately, but on my code I use System Create which in this test creates 3 enemies called "GooE". maybe that's the problem?

    But when I attack them, it works great... it won't reduce damage to all, but to each instance (and I didn't code anything special just reduced the damage) that's why I'm so confused now. :(

    In my game I must create / spawn the enemies randomly and not just putting them manually on the stage.

    So I'm guessing that's why "FOR EACH" isn't working, and it's not related to the function I did but it's only a guess... I'm still scratching my head while trying to think on a solution for this.

    Here are visuals of how it works on my current tests:

    When Player Attacks it works perfect: per instance. but when Player collide with the Enemy ALL Instances rracts instead of just the specific enemy:

    i.imgur.com/mTF1XDE.gif [/img]

    Also,it cause the 2nd issue which damage twice when collide with 2 enemies instead of just 1:

    i.imgur.com/9lXkVSP.gif [/img]

    If anyone have other ideas or suggestions, please share... I'm not sure what I'm doing wrong, please have a look above on my other code tests followed to other suggestions.

    Thanks ahead!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The function looses its reference to which instance was involved and therefore executes the action on all gooe objects.

    The second gif you posted, the point where you hit the second gooe, you actually hit 2. (I see 2 gooes behind one another)

    Also, in your events ... you have a timer on the player, then perform actions when the timer runs out on the gooes. those will effect all gooes as there is no reference to an individual one.

  • The function looses its reference to which instance was involved and therefore executes the action on all gooe objects.

    The second gif you posted, the point where you hit the second gooe, you actually hit 2. (I see 2 gooes behind one another)

    Also, in your events ... you have a timer on the player, then perform actions when the timer runs out on the gooes. those will effect all gooes as there is no reference to an individual one.

    Hey thanks for trying to help, I appreciate it.

    If you followed the thread you saw that even when I got rid of the functions, the result is the same. so it's not the issue.

    timer was on the function which are not relevant since I removed them for the sake of testing and I got the same result as you can see on the above GIF, so it's not where the bug is.

    2 hits, that's the issue... Player should hit once even if he jumps on 5 enemies.

    But again, why it works perfectly fine when I attack to reduce damage?

    when the player attacks 1 enemy, it reduce 1 HP, 2nd hit destroy it, but it won't destroy ALL ENEMIES which is exactly as it should be: individual for each enemy and I didn't put any code for it.

    While on collision, it will affect ALL ENEMIES instead of just the specific one... This is why I'm sooo confused.

    As a newbie, I'm guessing I need do something on the CREATE / SPAWN event to give each instance it's own ID? or something like that? again... I'm guessing.

    Is there an event I can add to the CREATE / SPAWN that will make each enemy individual?

    or it's not built-in and I need to do something more complicated with variables?

    Sorry about my bad English, thank you all for your kind help!

  • UPDATE:

    So after I removed the Function, I re-code the stop/freeze of the enemy, I didn't use "FOR EACH" and it works...

    So one issue solved, now every individual enemy collide with the player stops.

    i.imgur.com/jhsdncW.png [/img]

    But the other issue is still there: if the Player jumps on 2 enemies (normal collision) or 5 enemies, I will lose 2 HP or 5 HP!

    What I want: Lose only 1 HP if the player collide with any of this kind of enemy type "GooE" even if they are grouped together.

    So there is one solution mentioned with variables, but I wonder about different approach?

    can this be solved with the magic of "FOR EACH" ??

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