Exemplo n.º 1
0
        void OnTriggerEnter(Collider other)
        {
            var Root = other.transform.root;

            if (other.isTrigger && TriggerInteraction == QueryTriggerInteraction.Ignore)
            {
                return;                                                                                                                             //just collapse when is a collider what we are hitting
            }
            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitLayer))
            {
                return;                                                                      //Just hit what is on the HitMask Layer
            }
            if (Root == Owner.transform)
            {
                return;                                                                    //Don't hit yourself;
            }
            if (!AlreadyHitted.Find(item => item == Root))                                 //if the entering collider is not already on the list add it
            {
                AlreadyHitted.Add(Root);
            }

            if (Root == CurrentAnimal)
            {
                return;                                                           //if the animal is the same, do nothing we already done the logic below
            }
            else
            {
                if (CurrentAnimal)
                {
                    AlreadyHitted = new List <Transform>();                        //Clean the colliders if you had a previus animal
                }
                CurrentAnimal = Root;                                              //Is a new Animal that is enetering the Attack Trigger

                var TargetPos = Root.position;

                var mesh = Root.GetComponentInChildren <Renderer>();
                if (mesh != null)
                {
                    TargetPos = mesh.bounds.center;                                         //Get the mesh Bounds Center
                }
                Vector3 direction = (Owner.position - TargetPos).normalized;                //Calculate the direction of the attack

                var interactable = other.transform.GetComponent <IInteractable>();          //Get the Animal on the Other collider

                interactable?.Interact();

                enemy = Root.GetComponentInChildren <IMDamage>();                           //Get the Animal on the Other collider

                if (enemy != null)                                                          //if the other does'nt have the Damagable Interface dont send the Damagable stuff
                {
                    enemy.HitDirection = direction;
                    enemy.Damage();
                    EnemyStatEnter.ModifyStat(Root.GetComponentInChildren <Stats>()); //Affect Stats
                }
                else if (other.attachedRigidbody && PushForce != 0)                   //If the other has a riggid body and it can be pushed
                {
                    other.attachedRigidbody.AddForce(-direction * PushForce, ForceMode.VelocityChange);
                }
            }
        }
Exemplo n.º 2
0
        internal void SetDamageStuff(Vector3 OtherHitPoint, Transform other)
        {
            var Root = other.root;

            if (Root == transform.root)
            {
                return;                                               //if Im hitting myself
            }
            //Mount montura = other.GetComponentInParent<Mount>();
            //Mount OwnerMount = Owner.GetComponent<MRider>()?.Montura;
            //if (OwnerMount != null && montura == OwnerMount) return;          //Do not Hit your Mount

            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitLayer))
            {
                return;                                                                              //Just hit what is on the HitMask Layer
            }
            Debug.DrawLine(OtherHitPoint, meleeCollider.bounds.center, Color.red, 3f);

            if (canCauseDamage && !AlreadyHitted.Find(item => item == Root))                        //If can cause damage and If I didnt hit the same transform twice
            {
                AlreadyHitted.Add(Root);

                Rigidbody OtherRB = other.GetComponentInParent <Rigidbody>();

                var interactable = other.GetComponent <IInteractable>();
                interactable?.Interact();

                if (OtherRB)
                {
                    OtherRB.AddExplosionForce(MinForce * 50, OtherHitPoint, 5);
                }


                var mesh      = Root.GetComponentInChildren <Renderer>();
                var TargetPos = Root.position;
                if (mesh == null)
                {
                    TargetPos = mesh.bounds.center;
                }

                Vector3 direction = (OtherHitPoint - TargetPos).normalized;

                AffectStat.Value = Random.Range(MinDamage, MaxDamage);
                AffectStat.ModifyStat(Root.GetComponentInChildren <Stats>());                     //Affect Stats


                Damager.SetDamage(direction, Root, transform);

                PlaySound(3);     //Play Hit Sound when get something

                OnHit.Invoke(other.gameObject);

                if (!meleeCollider.isTrigger)
                {
                    meleeCollider.enabled = false;
                }
            }
        }
Exemplo n.º 3
0
        internal void SetDamageStuff(Vector3 OtherHitPoint, Transform other)
        {
            if (other.root == transform.root)
            {
                return;                               //if Im hitting myself
            }
            Mountable montura = other.GetComponentInParent <Mountable>();

            if (montura == Owner.Montura)
            {
                return;                           //if Im hitting my horse **New
            }
            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitMask))
            {
                return;                                                                   //Just hit what is on the HitMask Layer
            }
            DV = new DamageValues(meleeCollider.bounds.center - OtherHitPoint, Random.Range(MinDamage, MaxDamage));

            Debug.DrawLine(OtherHitPoint, meleeCollider.bounds.center, Color.red, 3f);


            if (canCauseDamage && !AlreadyHitted.Find(item => item == other.transform.root))                        //If can cause damage and If I didnt hit the same transform twice
            {
                AlreadyHitted.Add(other.transform.root);
                other.transform.root.SendMessage("getDamaged", DV, SendMessageOptions.DontRequireReceiver);         //To everybody who has GetDamaged()


                Rigidbody OtherRB = other.transform.root.GetComponent <Rigidbody>();

                if (OtherRB && other.gameObject.layer != 20)                                                        //Apply Force if the game object has a RigidBody && if is not an Animal
                {
                    OtherRB.AddExplosionForce(MinForce * 50, OtherHitPoint, 20);
                }

                PlaySound(3);                                                                                       //Play Hit Sound when get something

                OnHit.Invoke(other.gameObject);

                if (!meleeCollider.isTrigger)
                {
                    meleeCollider.enabled = false;
                }
            }
        }