void OnTriggerEnter(Collider other) { if (other.isTrigger) { return; //just collapse when is a collider what we are hitting } enemy = other.GetComponentInParent <IMDamagable>(); //Get the Animal on the Other collider if (enemy != null) //if the other does'nt have the animal script skip { if (myAnimal.GetComponent <IMDamagable>() == enemy) { return; //Don't Hit yourself } Vector3 direction = myAnimal.transform.position - other.bounds.center; //Calculate the direction of the attack DamageValues DV = new DamageValues(direction, damageMultiplier * (myAnimal ? myAnimal.attackStrength : 1)); enemy.getDamaged(DV); } else { if (other.attachedRigidbody && PushForce != 0) //If the other has a riggid body and it can be pushed { other.attachedRigidbody.AddForce((other.transform.position - transform.position).normalized * PushForce, ForceMode.VelocityChange); } } }
/// <summary> /// Find the direction hit vector and send it to the Damage Behavior with DamageValues /// </summary> public virtual void getDamaged(DamageValues DV) { if (Death) { return; //skip if is Death. } if (isTakingDamage) { return; //If is already taking damage skip... } if (inmune) { return; //skip if is imnune. } float damageTaken = DV.Amount - defense; OnGetDamaged.Invoke(damageTaken); life = life - damageTaken; //Remove some life actionID = -1; //If it was doing an action Stop!; if (life > 0) //If I have some life left play the damage Animation { damaged = true; //Activate the damage so it can be seted on the Animator StartCoroutine(IsTakingDamageTime(damageDelay)); //Prevent to take other hit after a time. _hitDirection = DV.Direction; } else { Death = true; } }
void OnTriggerEnter(Collider other) { if (other.transform.root == transform.root) { return; //Don't hit yourself } Vector3 direction = -other.bounds.center + GetComponent <Collider>().bounds.center; DamageValues DV = new DamageValues(direction, damageMultiplier * (myAnimal ? myAnimal.attackStrength : 1)); if (other.isTrigger) { return; // just collapse when is a collider what we are hitting } if (myAnimal) { if (myAnimal.IsAttacking) { myAnimal.IsAttacking = false; other.transform.SendMessageUpwards("getDamaged", DV, SendMessageOptions.DontRequireReceiver); } } else { other.transform.SendMessageUpwards("getDamaged", DV, SendMessageOptions.DontRequireReceiver); } }
/// Find the direction hit vector and send it to the Damage Behavior with DamageValues public virtual void getDamaged(DamageValues DV) { if (isTakingDamage) { return; //If is already taking damage skip... } // if (DV.Mycenter == DV.Theircenter) return; //If Im hitting MySelf skip... life = life - (DV.Amount - defense); //Remove some life if (life > 0) //If I have some life left play the damage Animation { damaged = true; //Activate the damage so it can be seted on the Animator StartCoroutine(isTakingDamageTime(0.2f)); //Prevent to take other hit in 0.2f // hitDirection = (-DV.Mycenter + DV.Theircenter).normalized; //Gets the Hit Direction Vector hitDirection = DV.Direction; } else { OnDeath(); Debug.Log(death); } }
public virtual void getDamaged(DamageValues DV) { if (animal) { animal.getDamaged(DV); } }
void OnTriggerEnter(Collider other) { if (other.transform.root == transform.root) { return; //Don't hit yourself } Vector3 direction = -other.bounds.center + Collider.bounds.center; DamageValues DV = new DamageValues(direction, damageMultiplier); if (other.isTrigger) { return; // just collapse when is a collider what we are hitting } IMDamagable Enemy = other.GetComponentInParent <IMDamagable>(); if (Enemy != null) { Enemy.getDamaged(DV); } }
void OnTriggerEnter(Collider other) { otherAnimal = other.GetComponentInParent <Animal>(); //Get the Animal on the Other collider if (!otherAnimal) { return; //if the other does'nt have the animal script skip } if (myAnimal == otherAnimal) { return; //Don't Hit yourself } Vector3 direction = myAnimal.transform.position - other.bounds.center; //Calculate the direction of the attack DamageValues DV = new DamageValues(direction, damageMultiplier * (myAnimal ? myAnimal.attackStrength : 1)); if (other.isTrigger) { return; //just collapse when is a collider what we are hitting } otherAnimal.getDamaged(DV); }
/// Find the direction hit vector and send it to the Damage Behavior without DamageValues public virtual void getDamaged(Vector3 Mycenter, Vector3 Theircenter, float Amount = 0) { DamageValues DV = new DamageValues(Mycenter - Theircenter, Amount); getDamaged(DV); }