public override bool DetectRadius() { // Runs the base function to check for objects in radius // Clear the list before checking everytime ObjectsInRange.Clear(); if (base.DetectRadius()) { foreach (GameObject detectedObj in ObjectsInRange) { if (targetObject != null) { if (targetObject == detectedObj) { isRunning = true; return(true); } } // if the player is detected in the objects in range if (detectedObj.tag == "Player") { // If the target object already exists // Don't have to reset the detected object // Focuses on one object at a time //Debug.Log("Target acquired"); targetObject = detectedObj; isRunning = true; return(true); } // if the kitten is detected in the objects in range else if (detectedObj.tag == "Kitten") { // idk what to do with this part yet lol // fuk i haven't coded in a long time // pee pee poo poo } // if not then it shouldn't care what objects it detected } } // if it isnt detecting anything // and it isnt moving // then reset it if (preyMovement.isMoving == false) { ResetTarget(); preyMovement.ResetMovement(); } return(false); }
void ResetTarget() { // Reset the target object to null targetObject = null; // Clear the list of objects ObjectsInRange.Clear(); // set the direction back to none targetDir = DIRECTIONS.NONE; isRunning = false; // Debug.Log("We'll get em next time"); }
public override bool DetectRadius() { // Clear the list before checking everytime ObjectsInRange.Clear(); // If base detected something in radius if (base.DetectRadius()) { // Loop through the detected objects foreach (GameObject detectedObj in ObjectsInRange) { // if target object already exist if (targetObject != null) { if (targetObject == detectedObj) { // make it run isRunning = true; return(true); } } // if it detects the prey if (detectedObj.tag == "Prey") { targetObject = detectedObj; isRunning = true; return(true); } // if it detects the player // it'll priorities the prey first if (detectedObj.tag == "Player") { // the cat is gonna be sad cause it sees its mother // i do this later // gsihgioahshapsdighaioghasdihpgioh } } } return(false); }
public override bool DetectRadius() { // Clear the objects in range if (ObjectsInRange.Count > 0) { ObjectsInRange.Clear(); } // If it detects any objects in it's radius if (base.DetectRadius()) { // if both are in the list at the same time // check if they are both within range to chase the cat if (ObjectsInRange.Contains(playerObject) && ObjectsInRange.Contains(kittenObject)) { DIRECTIONS playerDirection = GetTargetDirection(playerObject.transform.position); DIRECTIONS kittenDirection = GetTargetDirection(kittenObject.transform.position); // if both are clear // then both can chase the cat if (CheckIfClear(playerDirection, playerObject.transform.position) && CheckIfClear(kittenDirection, kittenObject.transform.position)) { // set the kitten object as the target // it should prioritise the kitten targetObject = kittenObject; targetDir = GetTargetDirection(); // is shocked should only trigger once // to stop it from repeating multiple times if (isTrapped == false) { isShocked = true; TrappedTilePosition = MapManager.Instance.GetWorldToTilePos(transform.position); } if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(true); } isTrapped = true; } else { isTrapped = false; } } else { isTrapped = false; } // if it is trapped, it shouldnt be able to do anything else if (isTrapped) { return(false); } //// If it already has a target that it is running from //if (targetObject != null) // return false; // Loop through the detected objects string successfulTag = ""; foreach (GameObject detectedObj in ObjectsInRange) { // It will only look for these two objects if (detectedObj.tag == "Player" || detectedObj.tag == "Kitten") { // Only detect when its idle if (characterState == STATE.IDLE) { //THIS IS A HACK, STORE PREV DATA GameObject PREVtargetObject = targetObject; DIRECTIONS prevTargetDir = targetDir; // Get the target object targetObject = detectedObj; // Check for the target direction targetDir = GetTargetDirection(); // Check if the path to the detected object is clear if (CheckIfClear(targetDir, targetObject.transform.position) == false) { // that target isnt available a danger to the mouse if (successfulTag == "") //if theres nothing just reset { StopMovement(); } //reset the data targetObject = PREVtargetObject; targetDir = prevTargetDir; // check the next if there is continue; } isShocked = true; if (detectedObj.tag == "Kitten") { if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(true); } } else { elapsedTime = 0.0f; } ////HACK PRIROTIZE KITTEN //if (successfulTag == "Kitten" && detectedObj.tag == "Player") //{ // targetObject = PREVtargetObject; // targetDir = prevTargetDir; //} //else //{ // // reset it if it tracks the player // if (detectedObj.tag == "Player") // elapsedTime = 0.0f; //} // Debug.Log("Mouse IsShocked Changed in line 197" + isShocked); successfulTag = detectedObj.tag; } // if it is a running state when it detects a enemy else if (characterState == STATE.RUNNING) { // if it detects a new enemy while running from the player if (detectedObj != targetObject && targetObject.tag == "Player") { DIRECTIONS detectedObjDir = GetTargetDirection(detectedObj.transform.position); // if the object detected is behind a wall // skip this object because it's not a threat if (CheckIfClear(detectedObjDir, detectedObj.transform.position) == false) { continue; } // it has to be shocked isShocked = true; // Debug.Log("Mouse IsShocked Changed in line 219" + isShocked); StartCoroutine(PlayerShockUITime()); StopMovement(); mouseMovement.StopMovement(); mouseMovement.ResetMovementList(); } } } // If it spots the player or kitten // it will try to run away //if (detectedObj.tag == "Player" || detectedObj.tag == "Kitten" ) //{ // // if it already has a target // if (targetObject != null) // { // // If it detects the kitten while being chased by the player // if (targetObject != detectedObj && targetObject.tag == "Player") // { // // Make it shocked // isShocked = true; // // stop both the movement // StopMovement(); // mouseMovement.StopMovement(); // mouseMovement.ResetMovementList(); // } // } // // Set the player object as it's current target // targetObject = detectedObj; // targetDir = GetTargetDirection(); // // Check the direction if its clear // // if it isn't then they detected an enemy through the wall // //if (CheckIfClear(targetDir) == false && targetObject.tag != "Player") // //{ // // if (characterState == STATE.RUNNING) // // { // // mouseMovement.ResetMovementList(); // // mouseMovement.StopMovement(); // // } // // StopMovement(); // // continue; // //} // // shocked // if (characterState != STATE.RUNNING) // isShocked = true; //} } //if (isShocked && characterState == STATE.IDLE) //{ // if (targetObject.tag == "Player") // StartCoroutine(PlayerShockUITime()); //} } else { isShocked = false; } //else //{ // characterState = STATE.IDLE; // targetObject = null; // targetDir = DIRECTIONS.NONE; //} return(false); }
public override bool DetectRadius() { // Clear the objets in the list incase if (ObjectsInRange.Count > 0) { ObjectsInRange.Clear(); } // Dont chase for targets when it's tired if (characterState == STATE.TIRED) { //ReturnToStart(); return(false); } // call the base class detect radius to get the list of objects in range if (base.DetectRadius()) { // Loop through the detected objects foreach (GameObject detectedObj in ObjectsInRange) { if (detectedObj.tag == "Prey") { // Only detect when idle if (characterState == STATE.IDLE) { targetObject = detectedObj; targetDir = GetTargetDirection(); // Check if the path to the detected object is clear if (CheckIfClear(targetDir, targetObject.transform.position) == false) { // that target isnt available a danger to the mouse StopMovement(); // check the next if there is continue; } isShocked = true; if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(true); } kittenMovement.UpdateAnimation(false, targetDir); // Debug.Log("Cat IsShocked Changed in line 123" + isShocked); } return(true); } } } else { if (mouseInSight == false) { isShocked = false; if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(false); } } // Debug.Log("Cat IsShocked Changed in line 134" + isShocked); } return(false); }