The Daily Click ::. Forums ::. Klik Coding Help ::. Hit detection and cooldown help

Post Reply  Post Oekaki 

Posted By Message

Jake T

11th July, 2011 at 03:01:37 -

Hi! First off thanks for taking the time to look at this, I really appreciate it.
I'm making a 2d sidescroller and i was wondering what would be the best way to set up a hit detection system. I had one that consisted of adding to an alterable value everytime an animation is played and the characters overlap until it reaches a value and then it deletes the enemy. It was very sloppy though and put multiple hits on the enemy when i only wanted one. I need help freezing the enemy after a hit has landed.
I also need help establishing a cooldown for when the player is hit similar to sonic or mario (when they blink after they're hit and are invulnerable for a few seconds).
I'm using the Newgrounds edition of TGF2.

Thanks so much for reading!

You're all awesome and everyone of you knows it.


Slow-Motion Riot


11th July, 2011 at 12:22:19 -

Maybe set it so that the enemy can be damaged only when a Flag is not tripped; as soon as the player's animation causes a hit on the enemy, the flag is tripped, and is reset once the player is no longer overlapping the enemy.

You can also make it flicker so that when the player is overlapping the enemy and the flag is tripped, the enemy flickers. The enemy will stop flickering once there is no overlap.

Not at my MMF2 computer at the moment so I can't test it out for you, but have a go at the above and see what happens.



Cornwall UK


VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th July, 2011 at 16:49:57 -

Jake, I see this is your first post, so Welcome to TDC!
I believe something like this ought to work:

// character hits player, unless they're still invincible
+ Enemy: hitTimer = 0
+ Enemy is overlapping Character
+ Character: animation "attack" is playing
+ Character: animation frame = whatever...
-> Enemy: set hitTimer to 150
-> Enemy: subtract 1 from hitPoints

// enemy still invincible
+ Enemy: hitTimer > 0
-> Enemy: subtract 1 from hitTimer
-> Enemy: freeze / blink / etc...

// enemy no longer invincible
+ Enemy: hitTimer > 0
-> return to normal...

// kill enemy
+ Enemy: hitPoints = 0
-> Enemy: destroy


Jake T

11th July, 2011 at 19:01:07 -

First of all, Thank you very much for responding.

The system works great! The hits register just fine and I couldn't be happier.

Thank you so much!!!

You're all awesome and everyone of you knows it.

Post Reply



Worth A Click