void Npc_investigate() { //Debug.Log("investigate"); npc_agent.isStopped = false; //resume walking, towards PC npc_agent.destination = tempdest.position; go_searchsign.SetActive(false); go_alertsign.SetActive(true); fl_detecting = 0; if (gameObject.GetComponentInChildren <GC_TriggerAI>().bl_pcinrange == false) //CHANGES for trigger { fl_losing += Time.deltaTime; if (fl_losing >= fl_losttime) { //Debug.Log("pc lost"); states = npc_states.search; } } else { go_player = GetComponentInChildren <GC_TriggerAI>().go_player; gameObject.transform.LookAt(go_player.transform); if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { if (hit.collider.gameObject.GetComponent <CharacterController>()) { fl_losing = 0; } } } }
void Npc_Wakeupself() { //Debug.Log("waking up"); go_sleepsign.SetActive(false); go_sleeptarget.SetActive(false); states = npc_states.search; }
void Npc_search() { Debug.Log("search"); fl_sleeping = 0; fl_losing = 0; go_alertsign.SetActive(false); if (fl_searching >= fl_searchtime) { go_searchsign.SetActive(false); states = npc_states.patrol; } else { fl_searching += Time.deltaTime; go_searchsign.SetActive(true); if (!npc_agent.pathPending && npc_agent.remainingDistance < 0.2f) { npc_agent.destination = transform.position + new Vector3(Random.Range(-fl_searchrange, fl_searchrange), 0, Random.Range(-fl_searchrange, fl_searchrange)); } if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { if (hit.collider.gameObject.GetComponent <CharacterController>()) { tempdest = hit.transform; states = npc_states.investigate; } } } }
void Npc_investigate() { Debug.Log("investigate"); npc_agent.isStopped = false; //resume walking, towards PC npc_agent.destination = tempdest.position; go_searchsign.SetActive(false); go_alertsign.SetActive(true); fl_detecting = 0; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { //if npc is not looking at PC - this will be changed with proper cone + raycast if (!hit.collider.gameObject.GetComponent <CharacterController>()) { fl_losing += Time.deltaTime; if (fl_losing >= fl_losttime) { Debug.Log("pc lost"); states = npc_states.search; } } else { //fl_losing = 0; change this later with finished AI } } if (npc_agent.remainingDistance == 0) { states = npc_states.search; } }
void Npc_patrol() { //Debug.Log("patrol"); tempdest = null; go_sleepsign.SetActive(false); fl_searching = 0; fl_losing = 0; if (go_grape != null) { if (Vector3.Distance(gameObject.transform.position, go_grape.transform.position) < fl_grapedistance) { tempdest = go_grape.transform; states = npc_states.investigate; } } if (!npc_agent.pathPending && npc_agent.remainingDistance < 0.2f) //needed for the agent to move smoothly from one point to another { npc_agent.destination = destinations[in_destpoint].position; in_destpoint = (in_destpoint + 1) % destinations.Length; //restart arrays after reaching last position } if (gameObject.GetComponentInChildren <GC_TriggerAI>().bl_pcinrange == true) //CHANGES for trigger { //Debug.Log("jackpot"); go_player = GetComponentInChildren <GC_TriggerAI>().go_player; gameObject.transform.LookAt(go_player.transform); Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * fl_RaycastLenght, Color.red); if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { if (hit.collider.gameObject.GetComponent <CharacterController>()) { //Debug.Log("PC hit"); fl_detecting += Time.deltaTime; //if the PC stays in sight of the agent for long enough, he becomes the target npc_agent.isStopped = true; tempdest = hit.transform; npc_agent.transform.LookAt(tempdest); //npc keeps looking at the pc go_alertsign.SetActive(true); //show exclamation point as visual feedback if (fl_detecting >= fl_detecttime) //if the pc stayed too long in sight { //npc_agent.destination = hit.rigidbody.position; // tempdest = hit.transform; states = npc_states.investigate; } } } } else { fl_detecting = 0; //reset detecting timer npc_agent.isStopped = false; //resume walking go_alertsign.SetActive(false); } }
void Npc_investigate() { //Debug.Log("investigate"); anim.SetBool("Investigate", true); npc_agent.isStopped = false; //resume walking, towards PC npc_agent.destination = tempdest.position; go_searchsign.SetActive(false); go_alertsign.SetActive(true); fl_detecting = 0; /*if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) * { //if npc is not looking at PC - this will be changed with proper cone + raycast * if (!hit.collider.gameObject.GetComponent<CharacterController>()) * { * * fl_losing += Time.deltaTime; * if (fl_losing >= fl_losttime) * { * Debug.Log("pc lost"); * states = npc_states.search; * } * } * else * { * //fl_losing = 0; change this later with finished AI * } * } * if (npc_agent.remainingDistance == 0) * { * states = npc_states.search; * }*/ if (gameObject.GetComponentInChildren <GC_TriggerAI>().bl_pcinrange == false) //CHANGES for trigger { fl_losing += Time.deltaTime; if (fl_losing >= fl_losttime) { //Debug.Log("pc lost"); anim.SetBool("Investigate", false); states = npc_states.search; } } else { go_player = GetComponentInChildren <GC_TriggerAI>().go_player; gameObject.transform.LookAt(go_player.transform); if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { if (hit.collider.gameObject.GetComponent <CharacterController>()) { fl_losing = 0; } } } }
void Npc_Sleeping() { Debug.Log("sleeping"); if (fl_sleeping < fl_sleeptime) { npc_agent.destination = new Vector3(transform.position.x, transform.position.y, transform.position.z); fl_sleeping += Time.deltaTime; go_sleepsign.SetActive(true); } else { go_sleepsign.SetActive(false); states = npc_states.search; } go_alertsign.SetActive(false); }
void Npc_search() { // Debug.Log("search"); anim.SetBool("Search", true); fl_sleeping = 0; fl_losing = 0; go_alertsign.SetActive(false); if (fl_searching >= fl_searchtime) { go_searchsign.SetActive(false); anim.SetBool("Search", false); states = npc_states.patrol; } else { fl_searching += Time.deltaTime; go_searchsign.SetActive(true); if (!npc_agent.pathPending && npc_agent.remainingDistance < 0.2f) { npc_agent.destination = transform.position + new Vector3(Random.Range(-fl_searchrange, fl_searchrange), 0, Random.Range(-fl_searchrange, fl_searchrange)); } /*if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) * { * if (hit.collider.gameObject.GetComponent<CharacterController>()) * { * tempdest = hit.transform; * states = npc_states.investigate; * } * }*/ if (gameObject.GetComponentInChildren <GC_TriggerAI>().bl_pcinrange == true) { go_player = GetComponentInChildren <GC_TriggerAI>().go_player; gameObject.transform.LookAt(go_player.transform); //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * fl_RaycastLenght, Color.red); if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, fl_RaycastLenght)) { if (hit.collider.gameObject.GetComponent <CharacterController>()) { tempdest = hit.transform; anim.SetBool("Search", false); states = npc_states.investigate; } } } } }