Example #1
0
        private void OnDamage(DamageInfo info, DamageablePart damageablePart)
        {
            Stimulation stim = null;

            if (info.sender != null)
            {
                stim = info.sender.GetComponentInChildren <Stimulation>();
            }

            if (owner != null && stim != null && (owner.CurrentInterest == null || owner.CurrentInterest.stimulation == null || owner.CurrentInterest.stimulation != stim))
            {
                AI_Interest interest = GetInterestIfExits(stim);

                if (interest != null)
                {
                    interest.lastKnowPosition = info.sender.transform.position;
                }

                else
                {
                    interest = new AI_Interest(stim, 0.35f);
                    interest.lastKnowPosition = info.sender.transform.position;
                    interest.inRange          = true;
                    interest.isAttackingMe    = true;

                    InterestList.Add(interest);
                }
            }
        }
Example #2
0
        public void Explode()
        {
            Collider[] colliderArray = Physics.OverlapSphere(transform.position, explosionRange);

            Dictionary <DamageablePart, DamageableManager> connections = new Dictionary <DamageablePart, DamageableManager>();

            for (int n = 0; n < colliderArray.Length; n++)
            {
                DamageablePart damageable = colliderArray[n].GetComponent <DamageablePart>();

                if (damageable != null && !connections.ContainsValue(damageable.Owner))
                {
                    float distance       = Vector3.Distance(transform.position, damageable.transform.position);
                    float distanceFactor = Mathf.Abs((distance / explosionRange) - 1.0f);     // a distance factor from 0.0f to 1.0f
                    //set the connection
                    connections[damageable] = damageable.Owner;

                    //create damage info
                    DamageInfo info = new DamageInfo();
                    info.hitForce        = explosionForce;
                    info.hitPoint        = transform.position;
                    info.explosionRadius = explosionRange;
                    info.upwardsModifier = upwardsModifier;
                    info.dmg             = dmg * distanceFactor;
                    info.damageType      = DamageType.Explosion;

                    //send damage event
                    damageable.DoDamage(info);
                }
                else
                {
                    Rigidbody rb = colliderArray[n].GetComponent <Rigidbody>();

                    if (rb != null)
                    {
                        ApplyImpactForce(rb);
                    }
                    else
                    {
                        VR_Grabbable grabbable = VR_Manager.instance.GetGrabbableFromCollider(colliderArray[n]);

                        if (grabbable != null && grabbable.RB != null)
                        {
                            ApplyImpactForce(grabbable.RB);
                        }
                    }
                }
            }


            Destroy(gameObject, 5.0f);
        }
Example #3
0
        private bool ThisDamageableIsMine(Damageable damageable)
        {
            if (damageableManager == null)
            {
                return(false);
            }

            if (!(damageable is DamageablePart))
            {
                return(false);
            }

            DamageablePart damageablePart = damageable as DamageablePart;

            return(damageablePart.Owner == damageableManager);
        }
 //called by DamageableParts to let the main entity know they exist
 public void RegisterSubpart(DamageablePart part)
 {
     subParts.Add(part);
 }