//A substate of Searching private void CheckingLastPosition() { //Debug.Log("Still checking position"); agent.destination = searchPosition; if (targetIsVisible) { ToChasing(); return; } //If we've reached the spot where we last heard/saw the player, check furniture if ((transform.position - searchPosition).magnitude < agent.stoppingDistance) { Collider2D hidingSpot = Physics2D.OverlapCircle(transform.position, 1.5f); if (hidingSpot != null && hidingSpot.transform.tag == "Furniture") { if (!hidingSpot.gameObject.GetComponent <Furniture_Controller>().GetIsEmpty()) { Debug.Log("Player Found!"); } } furnitureIndex = 0; searchTime = 0f; potentialFurniture = null; currentSearchingState = SearchingSubState.CheckingFurniture; return; } }
private void ToSearching() { //Reset all relevant variables, including the time we've been searching //(now zero), and where we last saw/heard the player. searchPosition = new Vector3(targetLocation.position.x, targetLocation.position.y, 0f); currentState = MonsterState.Searching; currentSearchingState = SearchingSubState.CheckingLastPosition; //CurrentStateText = "Current State: Searching"; //CurrentSubstateText = "SubState: None"; }
private void CheckingLastPosition() { monster.SetDestination(); if (monster.TargetIsVisible()) { ToMonsterChaseState(); return; } //Debug.Log("Test : " + (monster.transform.position - monster.searchPosition).magnitude + "\nStopping Distance: " + monster.agent.stoppingDistance); //If we've reached the spot where we last heard/saw the player, check furniture if ((monster.proxyLocation.position - monster.agent.destination).magnitude < furnitureCheckDistance)//TODO DELETE(monster.transform.position - monster.searchPosition).magnitude < (furnitureCheckDistance) || monster.agent.destination == monster.agent.transform.position) { Collider2D hidingSpot = Physics2D.OverlapCircle(monster.transform.position, 1.5f); if (hidingSpot != null && (hidingSpot.transform.tag == "Furniture" || hidingSpot.transform.tag == "HideObject")) { if (hidingSpot.gameObject.GetComponent <HideHero>().GetIsHiding()) { if (monster.debugInfo) { Debug.Log("Player found in hiding place"); } monster.soundManager.RandomizeSfx(monster.soundManager.openObject); hidingSpot.gameObject.GetComponent <HideHero>().LeaveObject(); monster.mainCamera.GetComponent <healthbar>().TakeDemage(monster.damageOnContact); } } furnitureIndex = 0; monster.furnitureSearchTime = 0f; potentialFurniture = null; realFurniture = new List <Collider2D>(); currentSubState = SearchingSubState.CheckingFurniture; return; } else if (monster.debugInfo) { //Debug.Log("Distance to Target: " + (monster.transform.position - monster.searchPosition).magnitude + " >= " + furnitureCheckDistance + "\nTarget: " + monster.searchPosition); Debug.Log("Proxy Position: " + monster.agent.transform.position + ", Proxy Destination: " + monster.agent.destination + ", proxyLocation " + monster.proxyLocation.position + "\nPosition = Destination = " + (monster.agent.destination == monster.agent.transform.position));//"\nMonster location: " + monster.transform.position + ", Monster destination: " + monster.searchPosition); } }
void Awake() { currentSubState = SearchingSubState.CheckingLastPosition; }