Пример #1
0
        public void OnMeleeDamage()
        {
            Collider[]          objectsInRange = Physics.OverlapSphere(transform.position, meleeRadius);
            List <Destructible> damagedObjects = new List <Destructible>(); // Keep track of what objects have been damaged so we don't do damage multiple times per collider.
            bool hasPlayedHitEffect            = false;

            foreach (Collider col in objectsInRange)
            {
                // Ignore terrain colliders
                if (col is TerrainCollider)
                {
                    continue;
                }

                // Ignore trigger colliders
                if (col.isTrigger)
                {
                    continue;
                }

                // Ignore the player's character controller (ie, don't allow hitting yourself)
                if (col is CharacterController && col.tag == "Player")
                {
                    continue;
                }

                if (!hasPlayedHitEffect) // Only play the hit effect once per melee attack.
                {
                    // Play hit effects
                    HitEffects hitEffects = col.gameObject.GetComponentInParent <HitEffects>();
                    if (hitEffects != null && hitEffects.effects.Count > 0)
                    {
                        hitEffects.PlayEffect(HitBy.Axe, transform.position, transform.forward * -1);
                    }

                    hasPlayedHitEffect = true;
                }

                // Apply impact force to rigidbody hit
                Rigidbody rbody = col.attachedRigidbody;
                if (rbody != null)
                {
                    rbody.AddForceAtPosition(transform.forward * 3f, transform.position, ForceMode.Impulse);
                }

                // Apply damage if object hit was Destructible
                Destructible destObj = col.gameObject.GetComponentInParent <Destructible>();
                if (destObj != null && !damagedObjects.Contains(destObj))
                {
                    damagedObjects.Add(destObj);
                    ImpactDamage meleeImpact = new ImpactDamage()
                    {
                        DamageAmount            = damageAmount, AdditionalForce = additionalForceAmount,
                        AdditionalForcePosition = transform.position, AdditionalForceRadius = additionalForceRadius
                    };
                    destObj.ApplyDamage(meleeImpact);
                }
            }
        }
Пример #2
0
    void OnTriggerEnter(Collider col)
    {
        if (target && col.transform == target.transform)
        {
            Impact();
            target.ApplyDamage(damage);

            if (target.destroyed && target.GetComponent <Aerolite>())
            {
                Messenger.Broadcast(MessageTypes.DestroyAeroliteByMissile);
            }
        }
    }
        public DamageResult AddDamage(float damage)
        {
            if (m_Multiplier > 0f)
            {
                int scaledDamage = Mathf.CeilToInt(damage * m_Multiplier);

                m_Destructible.ApplyDamage(scaledDamage);

                return(m_Critical ? DamageResult.Critical : DamageResult.Standard);
            }
            else
            {
                return(DamageResult.Ignored);
            }
        }
        public override DamageResult AddDamage(float damage, IDamageSource source)
        {
            if (source != null && !inDamageFilter.CollidesWith(source.outDamageFilter, FpsGameMode.friendlyFire))
            {
                return(DamageResult.Ignored);
            }

            if (base.AddDamage(damage, source) == DamageResult.Ignored)
            {
                return(DamageResult.Ignored);
            }
            ;

            m_Destructible.ApplyDamage(damage);
            return(DamageResult.Standard);
        }
Пример #5
0
        private void OnTriggerEnter(Collider col)
        {
            Destructible destObj = col.gameObject.GetComponentInParent <Destructible>();

            // If it has a rigidbody, apply force
            Rigidbody rbody = col.attachedRigidbody;

            if (rbody != null && !rbody.isKinematic)
            {
                rbody.AddExplosionForce(blastForce, origin, 0f, 0.5f);
            }

            // Check for Chip-Away Debris
            ChipAwayDebris chipAwayDebris = col.gameObject.GetComponent <ChipAwayDebris>();

            if (chipAwayDebris != null)
            {
                if (Random.Range(1, 100) > 50) // Do this about half the time...
                {
                    chipAwayDebris.BreakOff(blastForce, 0f, 0.5f);
                    return; //Skip the destructible check if the debris hasn't chipped away yet.
                }

                return;
            }

            // If it's a destructible object, apply damage
            if (destObj != null)
            {
                destObj.ApplyDamage(new ExplosiveDamage()
                {
                    DamageAmount   = damageAmount,
                    BlastForce     = blastForce,
                    Position       = origin,
                    Radius         = 0f,
                    UpwardModifier = 0.5f
                });
            }
        }
Пример #6
0
        public void ProcessBulletHit(RaycastHit hitInfo, Vector3 bulletDirection)
        {
            HitEffects hitEffects = hitInfo.collider.gameObject.GetComponentInParent <HitEffects>();

            if (hitEffects != null && hitEffects.effects.Count > 0)
            {
                hitEffects.PlayEffect(HitBy.Bullet, hitInfo.point, hitInfo.normal);
            }

            // Apply damage if object hit was Destructible
            Destructible destObj = hitInfo.collider.gameObject.GetComponentInParent <Destructible>();

            if (destObj != null)
            {
                ImpactDamage bulletImpact = new ImpactDamage()
                {
                    DamageAmount = Instance.bulletDamage, AdditionalForce = Instance.bulletForcePerSecond, AdditionalForcePosition = hitInfo.point, AdditionalForceRadius = .5f
                };
                destObj.ApplyDamage(bulletImpact);
            }

            Vector3 force = bulletDirection * (Instance.bulletForcePerSecond / Instance.bulletForceFrequency);

            // Apply impact force to rigidbody hit
            Rigidbody rbody = hitInfo.collider.attachedRigidbody;

            if (rbody != null)
            {
                rbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse);
            }

            // Check for Chip-Away Debris
            ChipAwayDebris chipAwayDebris = hitInfo.collider.gameObject.GetComponent <ChipAwayDebris>();

            if (chipAwayDebris != null)
            {
                chipAwayDebris.BreakOff(force, hitInfo.point);
            }
        }