//Charging collision void OnCollisionEnter(Collision coll) { //If the state is not charge do nothing if (state != State.Charge) { return; } MonsterAI m = coll.gameObject.GetComponent <MonsterAI>(); QuestObject QO = coll.gameObject.GetComponent <QuestObject>(); //If collision happened with a quest object if (m != null) { //If AI hit a sheep invoke the sheep hit function if (QO != null && m.GetType() == typeof(SheepAI)) { Debug.Log("I HIT A SHEEP"); HitSheep(QO, m, coll.gameObject, chargeForce * (accelTimer / accelTime), false, this); return; } //If its not a sheep it must be a static questObjective else if (m.GetType() == typeof(MeleeAI2)) { Debug.Log("Melee's collided with angle : " + Vector3.Dot(m.gameObject.transform.forward, transform.forward)); if (m.getState() == State.Charge && Vector3.Dot(m.gameObject.transform.forward, transform.forward) > 0.8) { return; } anim.SetTrigger("HitObject"); Debug.Log("hit another monster"); ChargeToMove(); } } else if (QO != null) { anim.SetTrigger("HitObject"); Debug.Log("Hit quest object"); QO.takeDamage(2, true, coll.contacts[0].point); base.playerAction.ObjectiveAttacked(this); ChargeToMove(); } else { anim.SetTrigger("HitObject"); Debug.Log("Hit wall"); agent.velocity = Vector3.zero; ChargeToMove(); } MeleeAttack(); }
void ProjectileCollision(GameObject collObj, Vector3 pos) { DestroyTarget(); setToDestroy = true; MonsterAI m = collObj.gameObject.GetComponent <MonsterAI>(); QuestObject questObj = collObj.GetComponent <QuestObject>(); if (m != null) { //other monsters if (m.GetType() == typeof(SheepAI)) { //let player know objective is attacked originMonster.HitSheep(m.GetComponent <QuestObject>(), m, m.gameObject, ExplosionForce, false, originMonster); return; } //other monsters else { m.Hit(1); Rigidbody body = collObj.GetComponent <Rigidbody>(); if (body) { body.AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius, 0f); } originMonster.playerAction.MonsterAttackedMonster(originMonster); } } if (questObj != null) { Debug.Log("QuestObject hitttiittitiit"); questObj.takeDamage(3, false, pos); //let player know objective is attacked originMonster.playerAction.ObjectiveAttacked(originMonster); } //monster should make daamge not the projectile?? if (collObj.CompareTag("Player")) { collObj.GetComponent <PlayerActionController>().PlayerAttacked(originMonster); Rigidbody body = collObj.GetComponent <Rigidbody>(); if (body) { body.AddExplosionForce(PlayerExplosionForce, transform.position, ExplosionRadius, 0f); } } }
//This is the function that makes the sheep go fly public void HitSheep(QuestObject QO, MonsterAI m, GameObject g, float force, bool useMosnsterOrigin, MonsterAI originMonster) { //Check the Quest Objective for nullpointer and if not make the sheep deed if (QO != null) { QO.takeDamage(999, false, Vector3.zero); if (originMonster != null) { playerAction.ObjectiveAttacked(this); } } //sheep goes fly m.ToDeath(); m.enabled = false; g.GetComponent <NavMeshAgent>().enabled = false; Rigidbody r = g.GetComponent <Rigidbody>(); r.drag = 0; r.mass = 1; if (useMosnsterOrigin) { r.AddExplosionForce(force, this.transform.position, 100f, 3); } else { r.AddExplosionForce(force, g.transform.position, 100f, 1); } r.AddTorque((this.transform.position - g.transform.position) * 10); g.GetComponentInChildren <Animator>().SetTrigger("Flying"); g.GetComponent <Sheep_flying>().flying = true; if (originMonster != null) { originMonster.playerAction.SheepAttacked(originMonster); } }
void Explode() { Debug.Log("I'm exploding"); if (explosionObject != null) { Instantiate(explosionObject, transform.position, Quaternion.identity); } //Checks for collision with different agents Collider[] Colliders = new Collider[0]; Colliders = Physics.OverlapSphere(transform.position, explosionRange); for (int i = 0; i < Colliders.Length; i++) { QuestObject QO = Colliders[i].gameObject.GetComponent <QuestObject>(); if (Colliders[i].tag == "Player") { //Player Debug.Log("This on is a player"); Vector3 vectorToCollider = (Colliders[i].transform.position - transform.position).normalized; Rigidbody body = Colliders[i].transform.GetComponent <Rigidbody>(); if (body) { body.AddExplosionForce(explosionForcePlayer, transform.position, explosionRange, 1f); } base.playerAction.PlayerAttacked(this); } else if (Colliders[i].tag == "Enemy") { MonsterAI m = Colliders[i].gameObject.GetComponent <MonsterAI>(); if (m != null) { if (m.GetType().Equals(typeof(SheepAI))) { //Sheep Debug.Log("I HIT A SHEEP"); HitSheep(QO, m, Colliders[i].gameObject, explosionForce, true, this); } else { //Other monsters base.playerAction.MonsterAttackedMonster(this); m.Hit(1); Rigidbody body = Colliders[i].transform.GetComponent <Rigidbody>(); if (body) { body.AddExplosionForce(explosionForcePlayer * 4, transform.position, explosionRange + 2, 0f); } } } } else { //Static object if (QO != null) { Debug.Log("Hit static quest object"); QO.takeDamage(5, true, Vector3.zero); base.playerAction.ObjectiveAttacked(this); } } } //Plays attack sound WwiseInterface.Instance.PlayGeneralMonsterSound(MonsterHandle.Suicide, MonsterAudioHandle.Attack, this.gameObject); base.Hit(99); }