private void OnTriggerEnter(Collider other) { if (player != null) { if (other.gameObject.tag == "Sardine") { this.gameObject.GetComponentInParent <NPCTankController>().SetTransition(Transition.SmelledSardine); npcScript.GetComponent <NPCTankController>().targetSardine = other.gameObject; npcScript.isEatingSardines = true; } } }
public override void Reason(Transform player, Transform npc) { NPCTankController npcScript = npc.GetComponent <NPCTankController>(); npcScript.detectionTimer += Time.deltaTime; if (npcScript.detectionTimer >= npcScript.detectionRate) { if (npcScript.aggroType.ToString() == "LineOfSight") { //RaycastHit hit; //npcScript.rayDirection = player.position - npc.position; //if ((Vector3.Angle(npcScript.rayDirection, npc.forward)) < npcScript.FieldOfView) //{ // // Detect if player is within the field of view // if (Physics.Raycast(npc.position, npcScript.rayDirection, out hit, npcScript.ViewDistance)) // { // //get aspect on the hit // Aspect aspect = hit.collider.GetComponent<Aspect>(); // if (aspect != null) // { // //Debug.Log("Hit something"); // if(aspect.aspectName == Aspect.aspect.Enemy) // { // Debug.Log("Enemy Seen"); // GameObject.FindWithTag("Player").GetComponent<PlayerScript>().isSeen = true; // npcScript.SetTransition(Transition.SawPlayer); // } // } // else // { // if (npcScript.CurrentStateID != FSMStateID.Patrolling) // npcScript.SetTransition(Transition.LostPlayer); // } // } //} } else if (npcScript.aggroType.ToString() == "Sound") { //if palyer is in list and is moving, else invoke transidtion to patorl after if (npcScript.canHearObjects.Contains(player.gameObject)) { if (npcScript.canHearObjects.Count < 2) { //100% chance npcScript.cantHearDebug = true; GameObject.FindWithTag("Player").GetComponent <PlayerScript>().isHeard = true; //npcScript.SetTransition(Transition.SawPlayer); } else { //Cuts chance in half depending on the amount of tanks in the list int randNum; randNum = Random.Range(1, 100); Debug.Log("testRand"); if (randNum < (100 / (npcScript.canHearObjects.Count * 5))) { npcScript.cantHearDebug = true; GameObject.FindWithTag("Player").GetComponent <PlayerScript>().isHeard = true; // npcScript.SetTransition(Transition.SawPlayer); } } } } else if (npcScript.aggroType.ToString() == "Touch") { } else if (npcScript.aggroType.ToString() == "Investigate") { if (npcScript.canHearObjects.Contains(player.gameObject)) { Debug.Log("Investigating"); npcScript.SetTransition(Transition.SmelledSardine); } } else { } npcScript.detectionTimer = 0; } if (Vector3.Distance(npc.position, player.position) <= 3.5f) { Debug.Log("Touched Player"); player.GetComponent <PlayerScript>().FoundPlayer(); npcScript.GetComponent <FieldOfView>().CatFoundPlayer(player); npcScript.agent.velocity = Vector3.zero; npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; npcScript.agent.isStopped = true; } if (Vector3.Distance(npc.position, waypoints[waypointCounter].position) <= 2.0f) { npcScript.agent.velocity = Vector3.zero; npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; npcScript.agent.isStopped = true; npcScript.pathingBuffer += Time.deltaTime; if (npcScript.pathingBuffer > 1f) { npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; npcScript.agent.isStopped = false; if (npcScript.pathing == PathingMode.Random) { Debug.Log("findnextrand"); FindNextRandPoint(); npcScript.agent.SetDestination(destPos); } else if (npcScript.pathing == PathingMode.Order) { if (waypointCounter < waypoints.Length - 1) { waypointCounter += 1; npcScript.agent.SetDestination(waypoints[waypointCounter].position); } else { waypointCounter = 0; npcScript.agent.SetDestination(waypoints[waypointCounter].position); } } npcScript.pathingBuffer = 0; } } }
public override void Reason(Transform player, Transform npc) { NPCTankController npcScript = npc.gameObject.GetComponent <NPCTankController>(); if (npcScript.targetSardine == null) { npcScript.agent.isStopped = false; investigateTime = 0; npcScript.findPointCounter = 0; Debug.Log("Waypoint count is" + waypointCounter); Debug.Log("Waypoing Length is" + waypoints.Length); //if (waypointCounter < waypoints.Length - 1) //{ // Debug.Log("+1"); // waypointCounter++; // npcScript.agent.SetDestination(waypoints[waypointCounter].position); //} //else //{ // Debug.Log("0"); // waypointCounter = 0; // npcScript.agent.SetDestination(waypoints[waypointCounter].position); //} npcScript.isEatingSardines = false; npcScript.SetTransition(Transition.LostPlayer); } else { distToSardine = Vector3.Distance(npc.position, npcScript.targetSardine.transform.position); investigateTime += Time.deltaTime; if (distToSardine <= 3.5f) { npcScript.agent.velocity = Vector3.zero; npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; npcScript.agent.isStopped = true; } if (investigateTime >= 6f) { investigateTime = 0; npcScript.findPointCounter = 0; //if (waypointCounter < waypoints.Length - 1) //{ // waypointCounter += 1; // npcScript.agent.SetDestination(waypoints[waypointCounter].position); //} //else //{ // waypointCounter = 0; // npcScript.agent.SetDestination(waypoints[waypointCounter].position); //} npcScript.agent.isStopped = false; npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; npcScript.isEatingSardines = false; npcScript.SetTransition(Transition.LostPlayer); } } }