Creating 2D attack hitboxes and flamethrower

I am trying to create a flamethrower like attack in 2d. That is, when the box collider is created, the enemy takes a certain damage overtime if the enemy stays within the box. Anyone know the best approach to this problem?

Also, currently, I am using OnTriggerEnter2D as part of the attacking process. By setting off trigger boxes on/off and using OnTriggerEnter2D to detect for “hits”. I wonder if I am creating hitboxes the right way… Any reply is greatly appreciated, thank you.

Edit: As you already know how I create my hitboxes, OnTriggerEnter2D clearly doesn’t work for flamethrower like attacks, since it only detects once and OnTriggerStay is too overkill.

My thought was to mention OnTriggerStay. Why do you say it’s overkill?
The only other option, off the top of my head is to set a flag for in & out and use update, but that is almost exactly the same thing…

Now that I think about it, OnTriggerStay might actually be not that bad after all. But still, I am wondering if there is anyway to make OnTriggerStay “hit” only, say… 8 times per second? Or there is other more effective ways to do this?

What I wanna do is make a box that hits only 8 times every sec to everything that’s stays within the box.

Ya, sure… I mean…Why not?
Think about what you need for that. A value that equals 1/8.
If anyone is in the trigger area, check for that time amount to have passed, and apply the damage.
reset the timer and continue.
You can skip the check if # of objects that can be affected in the trigger zone is 0.
This will have a small bias, in that if I enter 1/16th of a second after you, i will be damaged at the same time interval as you, but lol… still 8 times per second from there on out :slight_smile:
That make sense?

1 Like

Yea,that make sense. Thank you. :slight_smile:

:slight_smile: No problem. Glad that I could help. Good luck with your game.