collision issue

Hi everyone!

Thanks always for your answer! but I ask about collision again.

My situation is following.

  1. Hero swing a sword.
  2. Sword-attack deals damage which is divided by number targets being attacked.
  3. The shape of collision is a capsule.
  4. There is very several solution. but I think the simplest solution is to get list of collision object and then give damage which is divided.
  5. How do I get number targets being attacked using capsule-collision-check method? I don’t know how I do it with OnTrigger~ or OnCollision~ function.


OnCollisionEnter is sent to both objects that are colliding. You could have the sword keep track of how many times OnCollisionEnter is called and just divide the damage by that number. However, you might want to wait before applying the damage to allow additional colliders to get counted (otherwise the first object would get 100% damage, while the fourth would get 25%).

I think you can get colliders hit by using collision.contacts in OnCollisionEnter method of the sword. But this can be used if the sword hits them at the same time.