예제 #1
0
    // for human agents
    bool ApplyDamage(AgentHuman inAgent, Vector3 inExplosionPos, float inDmgMultiplier)
    {
        Vector3 tmp  = ClosestPoint.PointBounds(inExplosionPos, inAgent.CharacterController.bounds);
        float   dist = (inExplosionPos - tmp).sqrMagnitude;

        if (dist > damageRadius * damageRadius)
        {
            return(false);
        }

#if DEBUG
        DebugDraw.Diamond(Color.grey, 0.02f, tmp);
        DebugDraw.LineOriented(Color.grey, inExplosionPos, tmp, 0.04f);
#endif

        int idx = inAgent.ExplosionHitTargets != null ? inAgent.ExplosionHitTargets.Length : 0;

        while (idx-- > 0)
        {
            if (CheckHit(inAgent.ExplosionHitTargets[idx], inExplosionPos, ref tmp))
            {
                float coef = 1.0f - Mathf.Clamp01(Mathf.Sqrt(dist) / damageRadius);

                Damage  = BaseDamage * coef * inDmgMultiplier;
                Impulse = tmp;

                inAgent.SendMessage("OnExplosionHit", this, SendMessageOptions.DontRequireReceiver);

                return(true);
            }
        }

        return(false);
    }