public void Attack() { anim.SetTrigger("Attack"); CurrentTarget.GetComponent <Rigidbody>().AddForce((CurrentTarget.transform.position - transform.position).normalized * 500f, ForceMode.Impulse); //CurrentTarget.GetComponent<BasicController>().Die (); CurrentState = RoosterStates.ROAMING; }
private void PushBack(bool kill) { anim.SetTrigger("Attack"); foreach (Collider Player in NearbyPlayers) { if (Player != null) { Player.gameObject.GetComponent <Rigidbody> ().AddForce((Player.gameObject.transform.position - transform.position).normalized * 500f, ForceMode.Impulse); } //if (kill) { //Player.gameObject.GetComponent<BasicController>().Die (); //} } int RandomDestination = Random.Range(0, 4); switch (RandomDestination) { case 0: CurrentDestination = new Vector3(85f, 0, 85f); break; case 1: CurrentDestination = new Vector3(-85f, 0, 85f); break; case 2: CurrentDestination = new Vector3(85f, 0, -85f); break; case 3: CurrentDestination = new Vector3(-85f, 0, -85f); break; } CurrentState = RoosterStates.RESETTING; }
public void RoamingState() { CurrentState = RoosterStates.ROAMING; if (RoamingTimer < WalkingTime + WaitingTime) { RoamingTimer += Time.deltaTime; } if (RoamingTimer >= WalkingTime + WaitingTime) { anim.SetBool("Walking", true); float RandomX = Random.Range(-1f, 1f); float RandomZ = Random.Range(-1f, 1f); Vector3 CurrentDirection = new Vector3(RandomX, transform.position.y, RandomZ).normalized; CurrentDestination = transform.position + CurrentDirection * 30; RoamingTimer = 0; } else if (RoamingTimer > WalkingTime && RoamingTimer < (WalkingTime + WaitingTime)) { anim.SetBool("Walking", false); CurrentDestination = transform.position; } agent.speed = 1.5f; Debug.DrawLine(transform.position, CurrentDestination, Color.green); agent.SetDestination(CurrentDestination); }
private void PushBack(bool kill) { anim.SetTrigger("Attack"); foreach (Collider Player in NearbyPlayers) { if (Player != null) { Player.gameObject.GetComponent <Rigidbody> ().AddForce((Player.gameObject.transform.position - transform.position).normalized * 500f, ForceMode.Impulse); } //if (kill) { //Player.gameObject.GetComponent<BasicController>().Die (); //} } anim.SetBool("Vulnerable", false); AttackingTimer = 0f; VulnerableTimer = 0f; ResettingTimer = 0f; switch (Lives) { case 3: CurrentDestination = new Vector3(30f, 0, -30f); break; case 2: CurrentDestination = new Vector3(30f, 0, 30f); break; case 1: CurrentDestination = new Vector3(-30f, 0, -30f); break; } CurrentState = RoosterStates.RESETTING; }
// Use this for initialization void Start() { agent = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); CurrentDestination = transform.position; CurrentTarget = null; CurrentState = RoosterStates.ROAMING; }
// Use this for initialization void Start() { agent = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); CurrentDestination = Vector3.zero; CurrentTarget = null; CurrentState = RoosterStates.ROAMING; }
private void ChasingState() { CurrentState = RoosterStates.CHASING; anim.SetBool("Walking", true); movAgent.SetDestination(CurrentTarget.transform.position); movAgent.speed = ChasingSpeed; if (Vector3.Distance(transform.position, CurrentTarget.transform.position) < 1.5f) { SingleTargetAttack(); } }
//---------------------------------------------------------------- FSM States ---------------------------------------------------------------------- private void RoamingState() { CurrentState = RoosterStates.ROAMING; if (Vector3.Distance(transform.position, CurrentDestination) < 1f) { WalkingTime = 0f; } if (WalkingTime > 0f) { //cammina WalkingTime -= Time.deltaTime; anim.SetBool("Walking", true); movAgent.SetDestination(CurrentDestination); movAgent.speed = RoamingSpeed; } else if (WaitingTime > 0f) { //stai WaitingTime -= Time.deltaTime; anim.SetBool("Walking", false); movAgent.SetDestination(transform.position); movAgent.speed = 0f; } if (WalkingTime <= 0f && WaitingTime <= 0f) { ResetTimers(); int RandomDestination = Random.Range(0, 4); switch (RandomDestination) { case 0: CurrentDestination = new Vector3(20, 0, 20); break; case 1: CurrentDestination = new Vector3(-20, 0, 20); break; case 2: CurrentDestination = new Vector3(20, 0, -20); break; case 3: CurrentDestination = new Vector3(-20, 0, -20); break; } } }
public void RoamingState() { CurrentState = RoosterStates.ROAMING; /*if (EnemyInFOW()) { * * CurrentState = RoosterStates.CHASING; * return; * * } else {*/ if (RoamingTimer < WalkingTime + WaitingTime) { RoamingTimer += Time.deltaTime; } if (RoamingTimer >= WalkingTime + WaitingTime) { anim.SetBool("Walking", true); int RandomDestination = Random.Range(0, 4); switch (RandomDestination) { case 0: CurrentDestination = new Vector3(20, 0, 20); break; case 1: CurrentDestination = new Vector3(-20, 0, 20); break; case 2: CurrentDestination = new Vector3(20, 0, -20); break; case 3: CurrentDestination = new Vector3(-20, 0, -20); break; } RoamingTimer = 0; } else if (RoamingTimer > WalkingTime && RoamingTimer < (WalkingTime + WaitingTime)) { anim.SetBool("Walking", false); CurrentDestination = transform.position; } agent.speed = 1.5f; agent.SetDestination(CurrentDestination); //} }
private void VulnerableState() { CurrentState = RoosterStates.VULNERABLE; VulnerableTimer -= Time.deltaTime; if (Physics.OverlapSphereNonAlloc(transform.position, 2.5f, NearbyPlayers, PlayersLayer) > 0) { AttackingTimer -= Time.deltaTime; } else { AttackingTimer = 3f; } }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); movAgent = GetComponent <UnityEngine.AI.NavMeshAgent>(); CurrentDestination = new Vector3(20, 0, 20); CurrentTarget = null; CurrentState = RoosterStates.ROAMING; FSMState Roaming = new FSMState(); Roaming.stayActions.Add(RoamingState); FSMState Chasing = new FSMState(); Chasing.stayActions.Add(ChasingState); FSMState Resetting = new FSMState(); Resetting.stayActions.Add(ResettingState); FSMState Vulnerable = new FSMState(); Vulnerable.stayActions.Add(VulnerableState); FSMTransition TransitionEnemyInFOW = new FSMTransition(EnemyInFOW); FSMTransition TransitionEnemyOutOfSight = new FSMTransition(EnemyOutOfSight); FSMTransition TransitionEnemyInAttackRange = new FSMTransition(EnemyInAttackRange); FSMTransition TransitionRemoveALife = new FSMTransition(RemoveALife); FSMTransition TransitionReset = new FSMTransition(Reset); FSMTransition TransitionEndedReset = new FSMTransition(EndedReset); FSMTransition TransitionTrapped = new FSMTransition(InTrappedState); FSMTransition TransitionTriggeredAlarm = new FSMTransition(TriggeredAlarm); Roaming.AddTransition(TransitionEnemyInFOW, Chasing); Roaming.AddTransition(TransitionTrapped, Vulnerable); Chasing.AddTransition(TransitionEnemyOutOfSight, Roaming); Chasing.AddTransition(TransitionEnemyInAttackRange, Roaming); Chasing.AddTransition(TransitionTrapped, Vulnerable); Chasing.AddTransition(TransitionTriggeredAlarm, Roaming); Vulnerable.AddTransition(TransitionRemoveALife, Resetting); Vulnerable.AddTransition(TransitionReset, Resetting); Resetting.AddTransition(TransitionEndedReset, Roaming); fsm = new FSM(Roaming); ResetTimers(); }
public void ChasingState() { CurrentState = RoosterStates.CHASING; anim.SetBool("Walking", true); if (Vector3.Distance(CurrentTarget.transform.position, transform.position) < 1f) { Attack(); } else { agent.speed = 4f; agent.SetDestination(CurrentTarget.transform.position); } }
private void ResettingState() { CurrentState = RoosterStates.RESETTING; ResettingTimer -= Time.deltaTime; if (ResettingTimer >= 9f) { movAgent.SetDestination(transform.position); anim.SetBool("Walking", false); } else if (ResettingTimer < 9f) { anim.SetBool("Walking", true); movAgent.SetDestination(CurrentDestination); movAgent.speed = ResettingSpeed; } }
public void VulnerableState() { if (VulnerableTimer < 6f) { VulnerableTimer += Time.deltaTime; agent.SetDestination(transform.position); if (Physics.OverlapSphereNonAlloc(transform.position, 2.5f, NearbyPlayers, PlayersLayer) > 2) { AttackingTimer += Time.deltaTime; } else { AttackingTimer = 0f; } if (AttackingTimer > 3f) { anim.SetBool("Vulnerable", false); AttackingTimer = 0f; VulnerableTimer = 0f; CurrentState = RoosterStates.ROAMING; Lives--; if (Lives == 0) { //GG; } else { PushBack(false); } } } else { anim.SetBool("Vulnerable", false); VulnerableTimer = 0f; CurrentState = RoosterStates.ROAMING; PushBack(true); //Spinge tutti via e toglie una vita ai giocatori } }
private void ResettingState() { CurrentState = RoosterStates.RESETTING; ResettingTimer += Time.deltaTime; if (ResettingTimer <= 0.5f) { anim.SetBool("Walking", false); agent.SetDestination(transform.position); } if (ResettingTimer > 1f && ResettingTimer < 12f) { anim.SetBool("Walking", true); agent.speed = 8.5f; agent.SetDestination(CurrentDestination); } if (ResettingTimer >= 12f) { ResettingTimer = 0f; CurrentState = RoosterStates.ROAMING; } }
public void Trap() { CurrentState = RoosterStates.VULNERABLE; anim.SetBool("Vulnerable", true); }
public void Alarm(GameObject target) { CurrentTarget = target; CurrentState = RoosterStates.CHASING; }
public void Alarm(GameObject target) { CurrentDestination = target.transform.position; RoamingTimer = 0.1f; CurrentState = RoosterStates.ROAMING; }
public void AttackingState() { CurrentState = RoosterStates.ATTACKING; }