public static FollowPlayerState GetInstance() { if (_instance == null) { _instance = new FollowPlayerState(); } return(_instance); }
public override void Update(EnemyAgent agent) { if (Vector3.Distance(agent.GetNavMeshAgent().destination, agent.transform.position) < 2.5f) { agent.UpdateWaypoint(); } RaycastHit hit; if (Physics.SphereCast(agent.transform.position + new Vector3(0.5f, 0f, 0.5f), 1f, agent.transform.forward, out hit, agent.GetFollowRange())) { if (hit.collider.tag == "Player") { agent.SetState(FollowPlayerState.GetInstance()); } } }
public override void Update(EnemyAgent agent) { //check if player is in his way if yes follow player if (Vector3.Distance(agent.GetNavMeshAgent().destination, agent.transform.position) < agent.GetAttackRange() + 0.5f) { agent.SetState(AttackBaseState.GetInstance()); } RaycastHit hit; if (Physics.SphereCast(agent.transform.position + new Vector3(0.5f, 0.5f, 0.5f), 0.5f, agent.transform.forward, out hit, agent.GetFollowRange())) { if (hit.collider.tag == "Player") { agent.SetState(FollowPlayerState.GetInstance()); } } }
public override void Update(EnemyAgent agent) { //check if target still in attack range if yes attack again after ending the attack animation agent.SetPlayerTarget(); if (Vector3.Distance(agent.GetNavMeshAgent().destination, agent.transform.position) < agent.GetAttackRange()) { if (agent.GetCurrentTimeBtwAttacks() <= 0) { agent.Attack(); } else { agent.AdjustAttackTime(); } } else { agent.SetState(FollowPlayerState.GetInstance()); } }
private void MakeFSM() { Vector3 target = new Vector3(Random.Range(transform.position.x - 5.0f, transform.position.x + 5.0f), Random.Range(transform.position.y - 5.0f, transform.position.y + 5.0f)); RoamingState follow = new RoamingState(target); follow.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); FollowPlayerState chase = new FollowPlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowPath); chase.AddTransition(Transition.NearPlayer, StateID.AttackPlayer); ShootPlayerState attack = new ShootPlayerState(); attack.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); sm = new FSMSystem(); sm.AddState(follow); sm.AddState(chase); sm.AddState(attack); }