BeginOverlap Damage Per Second Loop?

Right now I have a capsule component on enemy characters. I want to make it so that while the enemy capsule component overlaps with my player component, it will do damage over time. The best example I can give is the PainCausingVolume. I want to deal damage to the player every second that the two capsules are overlapping.

To try and achieve this, I used OnComponentBeginOverlap and branches to start a timer before the enemy can attack again. However when multiple enemies are overlapping, they just add to the timer instead of having their own BP_Enemy Timer. I’m not sure if timers would be the best way to achieve this effect, but I’m still pretty new to game development.

Basically what I want to happen is that if the player touches an enemy, they will be damaged, but they can’t be damaged by the same enemy until 1 second passes. So each enemy touching the player would in theory have their own independent cooldown before they could attack the player again.

So you need the timer setup in the enemy parent, so each of the enemies has it.

Technically you could do it all in the player, be it’s too complicated.

The Attacker needs to implement its own timer.

Other option is On Begin Overlap store the actor ref and a game time to apply dmg in a struct array or Tmap.

Struct||TMap [ Actor Ref, DmgTime (game time + 1s) ]

On Tick run a check on the array/tmap to see if it is empty.

Not empty:
For each loop -> (DmgTime <= Game Time) -> Apply Dmg, Set DmgTime (Game time + 1s)

End Overlap:
Get actor ref -> Find its element in the array/tmap, apply dmg if need be, remove ref.

This method isn’t accurate enough to guarantee dmg will be applied at the exact 1 sec marker.

Alright, I think I figured it out!
I added in a CanAttack boolean that will set to true when the enemy spawns in, then it’ll turn off when the enemy attacks and delay for 1 second to allow for the enemy to attack again. The AttackPlayer event will handle the timer instead of the BeginOverlap, I think this solved pretty much all of my problems, but might look a bit redundant with AttackPlayer and DamagePlayer :thinking:

this way the edge of the AttackCapsule doesn’t apply again right after ending the overlap and starting again.

1 Like

Excellent :star_struck: