I have some units on the layout that chase each other. Once they're close to their target, they start an attack animation. At this animation's end, I would like to damage the units that are overlapping when (invisible) attack zone of the attacker.
What is the best way, more efficient, to do this ? Any idea ?
I came with two way :
You can't check for collision as collision event might happen while animation is still playing, so you need to check for overlapping.
Something like this:
Unit on animation "attack" ended
Unit is overlapping Enemy -> (deal damage to the enemy)
I do it with:
if animation frame = ( end frame of your animation's attack hit here ) and overlaping enemy = true
end frame because that is usually end of hitting or stabbing motion animation, but if you have a more complex animation you'd use whatever frame the hit/stab happens at.
I already do the same. But what would be the best way to do this for performance ? It seems that collision tests are better placed at top level event instead of inside a sub event.
Develop games in your browser. Powerful, performant & highly capable.
No, quite the opposite.
If your parent event is "animation has ended", and in the sub-event you check if objects are overlapping, then overlapping check will not be performed while animation is playing. So it will have zero impact on performance.
It's the same situation with "On collision" event, however since "On collision" is a triggered event (it only lasts for 1 tick), you should be careful when using it in sub-events.
dop2000, Thanks for the tip !