Bug with enemy immunity frames (SOLVED)

Greetings again,

In my game, I have a complex system for enemy immunity frames to make it work similarly to Terraria’s local immunity system:

Here’s how it works:

  1. Each attack (HarmfulThings group in this case) is given a UID when it’s created, and each enemy has a structure variable that keeps track of the UID of the attack that hit them
  2. If the bullet collides with an enemy, check this:
  • If the UID of the attack that hit them does not exist in their structure
    OR
  • If the UID DOES exist in the structure, AND if the Time from start is greater than the HarmfulThing’s UID that exists in the structure + 0.2
    (0.2 is the time the enemy is immune)
  1. Add the UID of the attack to the enemy’s structure, and deal damage

With this system, it makes sure the attack can only hurt an enemy every 0.2 seconds, and multiple attacks can hit an enemy, even if they are immune to the one that just hit them

Simply, the enemy becomes immune to that one instance of the attack for a brief time

It works very well for bullets and things. However, I have another object that exists in the HarmfulThings group. The player’s own attack

When I hit an enemy, there’s a very small random chance for the attack to hit the enemy twice:

This ONLY applies to the player’s attack. Nothing else in the group

Is there a way to patch this bug out? I’ve tried different things, but nothing seems to work

Does anybody have any ideas on what I can do to fix this? It’s driving me crazy

Let’s say papu zero have some experience in dealing damage

2023-12-04_06_00_jxhqHcxVqv_GDevelop

But i do not understand your idea
I am more than sure your issue comes from how you check if something can take damage
But i am unable to figure it out cause i did not deduce your method which kinda does look simple

I would need you to explain it in more detail

BUT 1 thing that strikes me you are checking time from start * layer time scale

Which is confusing you are multiplying value that is growing constantly by some static value which most likely is equal to 1
So basically you are most likely just doing
5 * 1
6 * 1
7 * 1 and so go on
Unless you have there something else in layer time scale than 1
So in other words you are simply checking if TimeFromStart saved in variable at the moment of hit is greater than TimeFromStart right now
Unless i am missing something

Yeah i would assume that is what you are doing since you added on end in condition +0.2
So that * layer time scale could simply be removed

Or am i wrong?

Alright, I tried removing it (I added it there to make sure the bullets don’t hurt the enemies while the game is paused)
Sadly, it changes nothing. I’m still getting the bug while other bullets work as intended:
issue
(Note: I placed 2 bullets on top of a dummy to demonstrate. Notice how my attack still sometimes hits twice, wheras the bullets work as intended)

I’ll explain how this works in more detail if if helps
Each thing that can hurt the player or an enemy is in a HarmfulThings group:


This group has the booleans “hurtPlayer” and “hurtEnemy,” which sets them to hurt either players or enemies respectively

The player’s attack has it’s own FSM. Basically, if the attack is on my player’s head, then it won’t hurt anyone. If I attack, the attack’s boolean “hurtEnemy” is true (Set back to false when it boomerangs back to me)

Since my attack belongs in the HarmfulThings group, the same code I provided above in the first post checks if the object has it’s “hurtEnemy” value set to true. If so, then check the I-frames code:

  1. Has this instance of HarmfulThings hurt this enemy yet?
  2. This instance of HarmfulThings DID hurt the enemy, and 0.2 seconds has passed since then?
    If the above is true, hurt the enemy

I can’t wrap my head around why the bullets work just fine, but my own attack has this bug


EDIT: More info if it helps. Explaining WHY I have it designed like this:

Let’s say I want a bunch of attacks to hit at once, like a flurry of bullets
If I remove the code here:


Then the attacks will hit the enemy every single frame, resulting in HUGE amounts of damage
issue

Likewise, if set up another way (Like with Trigger Once), each attack will then only hit once per enemy, then never again. Including my own attack. Also not ideal

Basically, it’s to make sure that each attack can ALWAYS hit


I’ve done some tinkering, and I think I found a culprit?
Here, there are no other enemy bullets on screen right now, and I’m getting consistent results:
issue

But if there ARE bullets on screen, then it starts getting the chance of dealing extra damage, especially if they hit other enemies…
issue

So I found the problem, other bullets are interfering with my attack. I just need to figure out a fix…

Does anyone have any ideas?

Well, I’ve FINALLY discovered what the issue was…

A bug in the engine… :skull:

So, here’s what the HarmfulThings group looks like:

Do you see the HurtBox and KillBox objects I highlighted?

They’re Tiled Sprite Objects

When first making the group, I tossed them in first, so they were all the top of the list, with bullets and Robirdy beneath them

Turns out, these two were interfering with how the HarmfulThings group calculates damage, simply because they were above everything else…

I moved them to the bottom, and just like magic, the bug is totally gone! It doesn’t matter how much stress I put the engine or the mechanics under now, it just straight up WORKS now:

So basically, the code WAS working this whole time. The problem is that I had Tiled Sprite Objects at the top of my group…

So uhhh, I just fixed the issue by accident, that took me all day to figure out, I have a headache…

So, PSA to anybody else reading this:

DO NOT USE TILED SPRITE OBJECTS IN GROUPS. LEARN FROM MY MISTAKES

Anyways, thanks for your help, I appreciate you coming in to give your guidance

2 Likes

Damn you
That is some lucky find

Look you mentioned trigger once not doing its job for multiple bullets

And without trigger once you are spamming damage

What i like to do

Condition
Bullet opacity = 255
Bullet is in collision with player
NO FAKING TRIGGER ONCE

Action
Change opacity of bullet set to 254
Change player variable HP subtract 1

Try it NEHHHEEEEEVER i had issue with bullet hitting more than once if i did not want it

Only thing to do is either give bullets now timers or variable which goes up or simply keep decreasing opacity

In each case if some value gets to some point you switch opacity back to 255

For example let’s try opacity

Condition
Bullet opacity = 255
Bullet is in collision with player
NO FAKING TRIGGER ONCE

Action
Change opacity of bullet set to 254
Change player variable HP subtract 1

Then
Bullet opacity is less than 255

Change bullet opacity subtract 0.2

And then
Bullet opacity is less than 250

Change bullet opacity set to 255

Same story with timers same story with variables
BBBBUT

AND i am explaining it to you cause i think this could be your alternative to excluding which bullet was already damaging player and which not
And that would ignore group variables which are not object variables but they are lately add on when variable system changed in gdevelop
SO i am assuming and i can be wrong that is why it allow damage to slip trough
As group thing they are checked last per order of your objects in group

But i can be wrong
But if i am right
Remember your GROUP have SOME variables
Not your objects which are in group

Well whatever good you figured it out

EDIT BELOW
I forgot to add
Since group variables are new thing and on top of that tiled sprites are even newer thing i would assume that order of their CHCK is last
And since you are checking GROUP and in your group tiled sprites were 1st
Check for them was performed last
Allowing them to NOT be checked in frame on which they should that is why damage could slip trough
BUT that again is just my assumption which can be totally wrong