About Damage Applying


I have a charactor with a sword whose attaking animation has two parts:

1: attacking (wield sword towards the enemy)

2: drawing back the sword

I think I can use collision to deal with damage calculating.

But, there's a problem..

In the first part of animation, the sword collides the enemy ,damage will be counted once,

in the second part of animation, the sword collides the enemy again,damage will be counted once more..

I don't want the damage to be counted twice..

I'm wondering if anyone can tell me what the best solution for it is~

Help me~

:) Thanks in advance!

You shouldn't use animations with colliders and triggers as the way to calculate damage done. While the benefits might be really apparent (near-perfect accuracy across the board), it's hard to forsee some of the problems you may encounter down the road (this being one of them).

Typically what games that have various melee weapons will do is, when the player swings, the game checks the distance between the two players (the one you're facing or pointing at, and you), and if you're "in range", then the damage is dealt. You could check the range twice for your particular setup, once in sync with the first swing, and once during the second swing. In fact, if you're using Unity's animation component, you can insert a function call at the exact moment the sword is supposed to hit (both times), and check the distance there.

Ironic, I just came up with that idea today! I was going to also use collision but if you touch an object you can hurt by acident... then you will have a problem.

you can do this :
make a boolean and call it only during the first animation then disable it
and add it to your OnCollisionEnter or wichone is and tell something like this :

if (theBoolean){

//then it can damage


this supposely can let you have the animation and the collision and the damage on all the time
more on you only need to make a smaller inplement to enable the boolean variable during the first animation then it stays turned off, i hope you get it