void Chase() { enemy.currentlyChasing = true; if (enemy.seePlayer || alwaysChase) { //get player position enemy.characterPostition = new Vector3(enemy.character.position.x, enemy.transform.position.y, enemy.character.position.z); //keep chasing until 2 away from player if (Vector3.Distance(enemy.transform.position, enemy.characterPostition) > 2) { //look at player enemy.transform.LookAt(enemy.characterPostition); //direction = enemy.target - enemy.transform.position; //move!! enemy.moveDirection = enemy.characterPostition - enemy.transform.position; enemy.moveDirection = enemy.moveDirection.normalized; enemy.GetComponent <Rigidbody> ().velocity = (enemy.transform.forward * 6f); } } else { if (alwaysChase == false) { StalkerState(); } } }
void Wander() { if (enemy.move) { enemy.target = enemy.wayPoint; enemy.target.y = enemy.transform.position.y; //enemy.transform.position.y; if (Vector3.Distance(enemy.transform.position, enemy.target) > 2) { targetTime -= Time.deltaTime; //Debug.Log ("Timer: " + targetTime); enemy.transform.LookAt(enemy.target); //direction = enemy.target - enemy.transform.position; enemy.direction = enemy.target - enemy.transform.position; enemy.direction = enemy.direction.normalized; enemy.GetComponent <Rigidbody> ().velocity = (enemy.transform.forward * 3f); //enemy.GetComponent<Rigidbody> ().AddForce(direction * 25f); //enemy.GetComponent<Rigidbody> ().AddForce (enemy.transform.forward * 15f, ForceMode.Force); } else { getwayPoint(); } if (targetTime <= 0.0f) { getwayPoint(); //time for preventing AI from being Stuck targetTime = 30.0f; } } /*else if (!enemy.move && enemy.hitWall) { * //BOUNCE BACK * enemy.lastPosition = enemy.transform.position - enemy.GetComponent<Rigidbody> ().velocity; * * if (Vector3.Distance (enemy.transform.position, enemy.lastPosition) > 5f) { * enemy.GetComponent<Rigidbody> ().velocity = -(enemy.transform.forward * 5f); * } else { * getwayPoint (); * enemy.hitWall = false; * enemy.move = true; * * } * /*enemy.lastPosition = enemy.transform.position - enemy.GetComponent<Rigidbody> ().velocity; * enemy.GetComponent<Rigidbody> ().AddForce(enemy.lastPosition * 5f); * if (Vector3.Distance (enemy.transform.position, enemy.lastPosition) > 0.5f) { * getwayPoint (); * enemy.hitWall = false; * } * * }*/ }
private void OnCollisionEnter(Collision col) { /* if (col.gameObject.tag == "Bullet" && wander.alive == true) * { * if (col.gameObject.GetComponent<BulletDeletion>().catType == BulletDeletion.AmmoType.RED) * { * Debug.Log("RED HAS COLLIDED"); * wander.move = false; * wander.GetComponent<Rigidbody>().freezeRotation = false; * this.GetComponent<Rigidbody>().AddForce(Vector3.forward * 200); * * } * // wander.move = false; * //wander.alive = false; * // wander.GetComponent<Rigidbody>().freezeRotation = false; * //this.GetComponent<EnemyStatePattern>().enabled = false; * * //this.GetComponent<EnemyStatePattern>().enabled = false; * //GetComponent<Rigidbody>().isKinematic = false; * }*/ if (col.gameObject.GetComponent <BulletDeletion>() != null && wander.move == true) { hitEffect.SetActive(true); timerStart = true; audio.PlayOneShot(success); //GetComponent<Rigidbody>().isKinematic = false; if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.PURPLE) { //Debug.Log("This is a Purple"); wander.alive = false; mutantObject.GetComponent <Rigidbody>().AddExplosionForce(280, col.transform.position, 100, 1); //enemyHealth -= 10; //THIS SHOULDNT KILL THE MUTANT Destroy(col.gameObject); //enemyHealth -= 10; //THIS SHOULDNT KILL THE MUTANT //rb.AddExplosionForce(power, explosionPos, radius, 3.0F); } wander.move = false; //Vector3 dir = col.contacts[0].point - transform.position; //Vector3 dir = transform.position - col.gameObject.transform.position; //dir = -dir.normalized; // Debug.Log(dir); // this.GetComponent<Rigidbody>().AddForce(dir*force); Destroy(col.gameObject); this.GetComponent <Rigidbody>().AddForce(Vector3.forward * 20); this.GetComponent <EnemyStatePattern>().enabled = false; //GetComponent<Rigidbody>().isKinematic = false; } if (col.gameObject.tag == "Bullet" && wander.move == false) { //GetComponent<Rigidbody>().isKinematic = false; if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.BLUE) { iceEffect.SetActive(true); timerStart = true; Destroy(col.gameObject); } if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.YELLOW) { Debug.Log("YELLOW BULLET ENTERED"); Destroy(col.gameObject); } if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.PURPLE) { // Debug.Log("This is a Purple"); //wander.alive = false; if (GetComponent <UnityEngine.AI.NavMeshAgent>() != null) { GetComponent <UnityEngine.AI.NavMeshAgent>().enabled = false; GetComponent <AgentWalkTo>().enabled = false; if (GetComponent <Rigidbody>().isKinematic == true) { GetComponent <Rigidbody>().isKinematic = false; this.GetComponent <Rigidbody>().AddForce(Vector3.forward * 500); } Invoke("DeleteMutant", 15); } mutantObject.GetComponent <Rigidbody>().AddExplosionForce(500, col.transform.position, 100, 200); Vector3 explosionPos = col.transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, 30); foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null && rb != this.GetComponent <Rigidbody>()) { rb.AddExplosionForce(150, explosionPos, 40, 2f); } } // enemyHealth -= 10; //THIS SHOULDNT KILL THE MUTANT Destroy(col.gameObject); //enemyHealth -= 10; //THIS SHOULDNT KILL THE MUTANT //rb.AddExplosionForce(power, explosionPos, radius, 3.0F); } /*if (col.gameObject.GetComponent<BulletDeletion>().catType == BulletDeletion.AmmoType.RED) * { * Debug.Log("RED HAS COLLIDED"); * col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero; * Destroy(col.gameObject); * //wander.move = false; * //wander.GetComponent<Rigidbody>().freezeRotation = false; * //this.GetComponent<Rigidbody>().AddForce(Vector3.forward * 200); * * }*/ wander.move = false; wander.alive = false; wander.GetComponent <Rigidbody>().freezeRotation = false; this.GetComponent <EnemyStatePattern>().enabled = false; } if (col.gameObject.tag == "Ammo" && wander.alive == true && col.gameObject.GetComponent <AmmoTypeScript>() != null) { if (col.gameObject.GetComponent <AmmoTypeScript>().catType == AmmoTypeScript.AmmoType.WHITE && col.gameObject.transform.position.y > transform.position.y) { mutantObject.GetComponent <Rigidbody>().freezeRotation = false; // this.GetComponent<Rigidbody>().isKinematic = false; mutantObject.GetComponent <EnemyStatePattern>().enabled = false; //this.GetComponent<Rigidbody>().isKinematic = false; mutantObject.GetComponent <Rigidbody>().AddForce(Vector3.forward * 200); wander.alive = false; } } }
private void OnCollisionEnter(Collision col) { /* if (col.gameObject.tag == "Bullet" && wander.alive == true) * { * if (col.gameObject.GetComponent<BulletDeletion>().catType == BulletDeletion.AmmoType.RED) * { * Debug.Log("RED HAS COLLIDED"); * wander.move = false; * wander.GetComponent<Rigidbody>().freezeRotation = false; * this.GetComponent<Rigidbody>().AddForce(Vector3.forward * 200); * * } * // wander.move = false; * //wander.alive = false; * // wander.GetComponent<Rigidbody>().freezeRotation = false; * //this.GetComponent<EnemyStatePattern>().enabled = false; * * //this.GetComponent<EnemyStatePattern>().enabled = false; * //GetComponent<Rigidbody>().isKinematic = false; * }*/ if (col.gameObject.GetComponent <BulletDeletion>() != null && wander.move == true) { //GetComponent<Rigidbody>().isKinematic = false; wander.move = false; //Vector3 dir = col.contacts[0].point - transform.position; //Vector3 dir = transform.position - col.gameObject.transform.position; //dir = -dir.normalized; // Debug.Log(dir); // this.GetComponent<Rigidbody>().AddForce(dir*force); Destroy(col.gameObject); this.GetComponent <Rigidbody>().AddForce(Vector3.forward * 20); //GetComponent<Rigidbody>().isKinematic = false; } if (col.gameObject.tag == "Bullet" && wander.move == false) { //GetComponent<Rigidbody>().isKinematic = false; if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.BLUE) { Destroy(col.gameObject); } if (col.gameObject.GetComponent <BulletDeletion>().catType == BulletDeletion.AmmoType.YELLOW) { Debug.Log("YELLOW BULLET ENTERED"); Destroy(col.gameObject); } /*if (col.gameObject.GetComponent<BulletDeletion>().catType == BulletDeletion.AmmoType.RED) * { * Debug.Log("RED HAS COLLIDED"); * col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero; * Destroy(col.gameObject); * //wander.move = false; * //wander.GetComponent<Rigidbody>().freezeRotation = false; * //this.GetComponent<Rigidbody>().AddForce(Vector3.forward * 200); * * }*/ wander.move = false; wander.alive = false; wander.GetComponent <Rigidbody>().freezeRotation = false; this.GetComponent <EnemyStatePattern>().enabled = false; } }
public WanderZone(EnemyStatePattern statePatternEnemy) { enemy = statePatternEnemy; enemy.GetComponent <Rigidbody> ().freezeRotation = true; enemy.hitWall = false; }