Пример #1
0
    private void DealDamageToTruck(Collision collision)
    {
        if (_timeSinceHit > MinTimeBetweenHits)
        {
            Debug.Log(collision.gameObject.name);
            if (collision.transform.CompareTag("DonutTruck") || collision.gameObject.CompareTag("AICar"))
            {
                ContactPoint contact    = collision.contacts[0];
                Vector3      inNorm     = contact.normal;
                Vector3      reflectDir = Vector3.Reflect(transform.forward, inNorm);

                //Angle between collison and collision plane normal
                float angleDeg = Vector3.Angle(inNorm, collision.relativeVelocity);
                float angleRad = angleDeg * Mathf.PI / 180;    // in radians

                float collisionStrength = Mathf.Cos(angleRad); // 0 - 1 range -> multiply this value by Some Force

                // Emit particles
                HitTruckParticles(collisionStrength, collision, reflectDir);

                // Drop flag
                GameObject.FindWithTag("AbilityManager").GetComponent <SCR_CaptureTheFlagg>().DropFlag(collision.relativeVelocity, collisionStrength);

                // Deal damage
                int damage = Mathf.RoundToInt(collisionStrength * collision.relativeVelocity.magnitude);
                DestructionManager.TakeDamage(damage);
                _timeSinceHit = 0;
            }
        }
    }
    private void Explode()
    {
        if (_timeBombState != TimeBombState.ACTIVATED)
        {
            return;
        }

        _timeBombState = TimeBombState.DETONATED;

        EnableActivateParticles(true);

        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, _radius);
        foreach (Collider col in colliders)
        {
            Rigidbody rb = col.GetComponent <Rigidbody>();
            if (rb != null)
            {
                if (rb.CompareTag("DonutTruck"))
                {
                    SCR_TruckDestructionManager truckDestrManager = col.GetComponent <SCR_TruckDestructionManager>();

                    // Calc damage
                    Vector3 truckPos = rb.position;
                    float   distance = (explosionPos - truckPos).magnitude;
                    float   damage   = (distance / _radius) * _maxDamage;

                    truckDestrManager.TakeDamage(damage);

                    rb.AddExplosionForce(_strength * _truckStrengthMultiplier, explosionPos, _radius);
                }
                else if (!rb.CompareTag("PoliceCar"))
                {
                    rb.AddExplosionForce(_strength, explosionPos, _radius);
                    _SoundHolder.GetComponent <SCR_AudioManager>().PlaySound(_SoundHolder.GetComponent <SCR_AudioManager>().GetSoundEffects()[9], GameObject.FindWithTag("PoliceCar"));
                }
            }
        }
    }