void UpdateState() { switch (state) { case BotState.IDLE: if (Input.GetMouseButtonDown(0)) { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(r, out hit)) { agent.SetDestination(hit.point); } } if (Input.GetMouseButtonDown(1)) { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(r, out hit)) { Vector3 dir = hit.point - transform.position; bot.ShootInDirection(dir); } } // debug pour afficher si on voit notre drapeau et éventuellement son porteur bool sees_flag = bot.CanSeeObject(team.team_flag.gameObject); bool sees_carrier = false; int carrier_ID = master.GetFlagCarrierID(team.team_ID); if (carrier_ID != -1 && bot.CanSeeObject(master.GetBotFromID(carrier_ID))) { sees_carrier = true; } GizmosService.Text("flag ? " + sees_flag, transform.position - Vector3.right * 4); GizmosService.Text("carrier ? " + sees_carrier, transform.position - Vector3.right * 8); GizmosService.Cone(transform.position, transform.forward, transform.up, 100, 70); break; } }
void Update() { GizmosService.Text(state.ToString(), transform.position + Vector3.forward, 0.01f, Color.white); score = master.GetScore(bot.team_ID); // récupère le score GizmosService.Cone(transform.position, transform.forward, Vector3.up, 10, 70); // --> affiche le cône de vision //LetGo(); // --> CheckFlag(); // --> si je porte le drapeau, passe en mode ReturnHomeWithFlag UpdateState(); // --> exécute les instructions de chaque état //SearchForFlag(); // --> chercher le drapeau allié si je ne le vois pas CheckEnnemy(); // --> permet de tier sur les ennemis if (bot.is_dead == true) { SwitchState(BotState.IDLE); // --> si je suis mort, passe dans l'état Idle team.SendMessageToTeam("ImDead"); // --> si je veux envoyer un message à ma mort } }
void Update() { GizmosService.Cone(transform.position, transform.forward, Vector3.up, 10, 70); if (comportement != "Camping" && comportement != "Go to the camping") { CampingChange(); } detection(); IsTheFlagInOurBase(); IsThereAnAlly(); ChangeYourComportement(); switch (comportement) { case "Flag": // va directement vers le drapeau enemi agent.SetDestination(team.enemy_base.position); if (bot.team_ID == 0) { if (master.flag_carriers [1] != -1) { if (toKill != null) { comportement = "Go to enemies"; } } } else if (bot.team_ID == 1) { if (master.flag_carriers [0] != -1) { if (toKill != null) { comportement = "Go to enemies"; } } } else if (toKill != null) { comportement = "Hit and run"; } break; case "Hit and run": //continue à aller vers le drapeau enemi tout en tirant sur les adversaires agent.SetDestination(team.enemy_base.position); shoot(); if (toKill == null) { comportement = "Flag"; } if (IsThereAnAlly()) { enterBattle = false; comportement = "Battle"; } break; case "Battle": // si il a un allié avec lui, rentre en mode combat, il se décale sur les cotés et tir if (!enterBattle) { positionBattle = transform.position; enterBattle = true; } shoot(); if (enterBattle) { if (toKill != null && Mathf.Abs(toKill.transform.position.x - transform.position.x) > Mathf.Abs(toKill.transform.position.z - transform.position.z)) { if (minusBattle) { agent.SetDestination(new Vector3(positionBattle.x - 8, 0, positionBattle.z)); if (Vector3.Distance(new Vector3(positionBattle.x - 8, 0, positionBattle.z), transform.position) < 1) { minusBattle = false; } } else if (!minusBattle) { agent.SetDestination(new Vector3(positionBattle.x + 8, 0, positionBattle.z)); if (Vector3.Distance(new Vector3(positionBattle.x + 8, 0, positionBattle.z), transform.position) < 1) { minusBattle = true; } } } else { if (minusBattle) { agent.SetDestination(new Vector3(positionBattle.x, 0, positionBattle.z - 8)); if (Vector3.Distance(new Vector3(positionBattle.x, 0, positionBattle.z - 8), transform.position) < 1) { minusBattle = false; } } else if (!minusBattle) { agent.SetDestination(new Vector3(positionBattle.x, 0, positionBattle.z + 8)); if (Vector3.Distance(new Vector3(positionBattle.x, 0, positionBattle.z + 8), transform.position) < 1) { minusBattle = true; } } } } if (!IsThereAnAlly()) { //si il n'a plus d'allié, va au drapeau enemi comportement = "Hit and run"; } if (toKill == null) { //si il a encore un allié va a la dernière position occupé par l'enemi comportement = "Poursuit enemi"; } break; case "Poursuit enemi": // va a la dernière position occupé par la cible if (toKill == null) { agent.SetDestination(lastPosition); if (transform.position == lastPosition) { comportement = "Flag"; } } if (toKill != null) { //si il retrouve la cible, retourne en mode combat enterBattle = false; comportement = "Battle"; } break; case "Take their flag": // Ramasse le drapeau enemi si il est a terre agent.SetDestination(WhereIsTheirFlag); shoot(); if (!TheirFlagIsDown) { comportement = "Flag"; } break; case "Save our flag": // ramasse notre drapeau si il est a terre et pas sur notre base agent.SetDestination(WhereIsOurFlag); shoot(); if (!OurFlagIsDown) { comportement = "Flag"; } break; case "Protect": //suit le porteur de drapeau allié shoot(); if (bot.team_ID == 0) { if (master.flag_carriers [1] == -1) { comportement = "Flag"; } else { agent.SetDestination(GameObject.Find("bot-" + master.flag_carriers [1] + "_team-" + bot.team_ID).transform.position); } } else if (bot.team_ID == 1) { if (master.flag_carriers [0] == -1) { comportement = "Flag"; } else { agent.SetDestination(GameObject.Find("bot-" + master.flag_carriers [0] + "_team-" + bot.team_ID).transform.position); } } break; case "SearchBegin": //cherche l'endroit le plus proche parmi un tableau de position float near = 9999999; for (int i = 0; i < positionSearch.Length; i++) { if (Vector3.Distance(positionSearch [i], transform.position) < near) { near = Vector3.Distance(positionSearch [i], transform.position); nearest = i; } } comportement = "Search"; break; case "Search": // se déplace de point en points jusqu'a trouver quelquechose agent.SetDestination(positionSearch [nearest]); if (bot.team_ID == 0) { if (Vector3.Distance(positionSearch [nearest], transform.position) < 5f) { nearest++; if (nearest >= positionSearch.Length) { nearest = 0; } } } if (bot.team_ID == 1) { if (Vector3.Distance(positionSearch [nearest], transform.position) < 5f) { nearest--; if (nearest <= -1) { nearest = positionSearch.Length - 1; } } } if (toKill != null) { comportement = "Go to enemies"; } break; case "Go to enemies": // se raproche des enemis si il est top loin shoot(); if (Vector3.Distance(lastPosition, transform.position) > 25f) { agent.SetDestination(lastPosition); } else { enterBattle = false; comportement = "Battle"; } break; case "Go to the camping": float nearCamping = 9999999; /* * if (Vector3.Distance (transform.position, master.spawn_points [team.team_ID].transform.position) > 15f) { * if (team.team_ID == 0) { * for (int i = 0; i < 4; i++) { * Debug.Log ("Camping 2"); * if (Vector3.Distance (positionCampingBottom [i], transform.position) < nearCamping) { * Debug.Log ("Camping 3"); * near = Vector3.Distance (positionCampingBottom [i], transform.position); * nearestCamping = i; * } * } * } else if (team.team_ID == 1) { * for (int i = 0; i < positionCampingTop.Length; i++) { * if (Vector3.Distance (positionCampingTop [i], transform.position) < nearCamping) { * near = Vector3.Distance (positionCampingTop [i], transform.position); * nearestCamping = i; * } * } * } * } else { */ nearestCamping = 0; //} Debug.Log(comportement); clampRotate = false; comportement = "Camping"; Debug.Log(comportement); break; case "Camping": Debug.Log(nearestCamping); if (nearestCamping < positionCampingTop.Length) { if (team.team_ID == 0) { agent.SetDestination(positionCampingBottom [nearestCamping]); } else if (team.team_ID == 1) { agent.SetDestination(positionCampingTop [nearestCamping]); } } if (bot.team_ID == 0) { if (nearestCamping < positionCampingBottom.Length && Mathf.Abs(Vector3.Distance(positionCampingBottom [nearestCamping], bot.transform.position)) < 3f) { nearestCamping++; } } else if (bot.team_ID == 1) { if (nearestCamping < positionCampingTop.Length && Mathf.Abs(Vector3.Distance(positionCampingTop [nearestCamping], bot.transform.position)) < 3f) { nearestCamping++; } } if (nearestCamping >= positionCampingTop.Length && !clampRotate) { agent.enabled = false; bot.transform.localEulerAngles = new Vector3(0, Mathf.Round(bot.transform.localEulerAngles.y), 0); clampRotate = true; agent.enabled = true; } shoot(); break; case "Go to base": // seul le porteur de drapeau peut entrer dans cet état, il retourne a sa base agent.SetDestination(team.team_base.position); shoot(); if (bot.team_ID == 0) { if (master.flag_carriers [1] != bot.ID) { comportement = "Flag"; } } else if (bot.team_ID == 1) { if (master.flag_carriers [0] != bot.ID) { comportement = "Flag"; } } break; } lastPosition1FrameAgo = lastPosition; toKill1FrameAgo = toKill; }
private void Feedbacks() { GizmosService.Text(state.ToString() + bot.can_shoot.ToString(), transform.position + Vector3.forward, 0.01f, Color.white); GizmosService.Cone(transform.position, transform.forward, Vector3.up, 10, 70); }
void Update() { GizmosService.Cone(transform.position, bot_object.transform.forward, Vector3.up, 10, 70); // --> affiche le cône de vision //UpdateState(); //Update Perception ThisIsWhatISee(); // STRATEGIE ATTACK FLAG if (teamController.teamStrategy == TeamBehaviourDeusVult.TeamStrategy.AttackFlag) { if ((state != BotState.DefenseProtectBase || state != BotState.DefensePlantATent) && master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { if (state == BotState.DefenseProtectBase) { teamController.flagDefenser = teamController.GetCloser(team.team_base.position); teamController.flagDefenser.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefenseProtectBase); } else if (state == BotState.DefensePlantATent) { Vector3 posCamping = Vector3.zero; if (teamId == 1) { posCamping = teamController.posCamping1; } else { posCamping = teamController.posCamping0; } teamController.sideCamper = teamController.GetCloser(posCamping); teamController.sideCamper.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefensePlantATent); } SwitchState(BotState.AttackBringFlagBack); } if (state != BotState.DefenseProtectBase && state != BotState.DefensePlantATent) { if (!teamController.weStoleTheirFlag) { SwitchState(BotState.AttackGetFlag); } else if (teamController.weStoleTheirFlag) { if (master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { teamController.flagCarrier = this; SwitchState(BotState.AttackBringFlagBack); } else { SwitchState(BotState.AttackHelpFlagGetter); } Debug.Log(master.GetFlagCarrierID((teamId + 1) % 2) + ", " + bot.ID + ", " + teamId); } } GetComponent <DeusVultStrategyAttackFlag> ().Act(); } else if (teamController.teamStrategy == TeamBehaviourDeusVult.TeamStrategy.Defense) { if ((state != BotState.DefenseProtectBase || state != BotState.DefensePlantATent) && master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { if (state == BotState.DefenseProtectBase) { teamController.flagDefenser = teamController.GetCloser(team.team_base.position); teamController.flagDefenser.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefenseProtectBase); } else if (state == BotState.DefensePlantATent) { Vector3 posCamping = Vector3.zero; if (teamId == 1) { posCamping = teamController.posCamping1; } else { posCamping = teamController.posCamping0; } teamController.sideCamper = teamController.GetCloser(posCamping); teamController.sideCamper.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefensePlantATent); } SwitchState(BotState.AttackBringFlagBack); } if (state != BotState.DefenseProtectBase && state != BotState.DefensePlantATent) { if (!teamController.weStoleTheirFlag) { SwitchState(BotState.AttackGetFlag); } else if (teamController.weStoleTheirFlag) { if (master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { teamController.flagCarrier = this; SwitchState(BotState.AttackBringFlagBack); } else { SwitchState(BotState.AttackHelpFlagGetter); } //Debug.Log (master.GetFlagCarrierID ((teamId + 1) % 2) + ", " + bot.ID +", " + teamId); } } GetComponent <DeusVultStrategyDefense> ().Act(); } else if (teamController.teamStrategy == TeamBehaviourDeusVult.TeamStrategy.Advanced) { if ((state != BotState.DefenseProtectBase || state != BotState.DefensePlantATent) && master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { if (state == BotState.DefenseProtectBase) { teamController.flagDefenser = teamController.GetCloser(team.team_base.position); teamController.flagDefenser.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefenseProtectBase); } else if (state == BotState.DefensePlantATent) { Vector3 posCamping = Vector3.zero; if (teamId == 1) { posCamping = teamController.posCamping1; } else { posCamping = teamController.posCamping0; } teamController.sideCamper = teamController.GetCloser(posCamping); teamController.sideCamper.GetComponent <BotBehaviourDeusVult> ().SwitchState(BotBehaviourDeusVult.BotState.DefensePlantATent); } SwitchState(BotState.AttackBringFlagBack); } if (state != BotState.DefenseProtectBase && state != BotState.DefensePlantATent) { if (!teamController.weStoleTheirFlag) { SwitchState(BotState.AttackGetFlag); } else if (teamController.weStoleTheirFlag) { if (master.GetFlagCarrierID((teamId + 1) % 2) == bot.ID) { teamController.flagCarrier = this; SwitchState(BotState.AttackBringFlagBack); } else { SwitchState(BotState.AttackHelpFlagGetter); } //Debug.Log (master.GetFlagCarrierID ((teamId + 1) % 2) + ", " + bot.ID +", " + teamId); } } GetComponent <DeusVultStrategyAdvanced> ().Act(); } //GizmosService.Cone(bot_object.transform.position, bot_object.transform.forward, Vector3.up, 10, 70); }