protected override void BuildFSM() { PatrolState patrol = new PatrolState(PatrolPoints, navAgent, agroDistance); patrol.AddTransitionState(FSMStateID.Shoot, FSMTransitions.SawPlayer); patrol.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); ShootState shoot = new ShootState(retreatDistance, spawnerScript); shoot.AddTransitionState(FSMStateID.Patrol, FSMTransitions.PlayerOutOfRange); shoot.AddTransitionState(FSMStateID.Retreat, FSMTransitions.PlayerTooClose); shoot.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); RetreatState retreat = new RetreatState(navAgent, retreatDistance); retreat.AddTransitionState(FSMStateID.Shoot, FSMTransitions.CloserDistanceReached); retreat.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); DeadState dead = new DeadState(); AddFSMState(patrol); AddFSMState(shoot); AddFSMState(retreat); AddFSMState(dead); }
private static RetreatState _instance; //only declared once private RetreatState() //set instance to itself { if (_instance != null) { return; } _instance = this; }
// Update is called once per frame void Update() { //if you arn't near the player then don't do anything if (PlayerDistance() > 8) { return; } //do action based on retreatState switch (retreatState) { case RetreatState.ACTIVATING: anim.SetInteger("State", 1); myBase.myRigid.velocity = Vector2.zero; doAction(); retreatState = RetreatState.RETREATING; break; case RetreatState.RETREATING: anim.SetInteger("State", 0); if (myBase.player) { sprite.flipX = !(myBase.player.transform.position.x < transform.position.x); } myBase.myStats.currentHP = 1; //check if far enough away from the player if (PlayerDistance() > retreatDistance) { retreatState = RetreatState.COOLDOWN; SetTarget(actCooldownTime); } else { //Debug.Log(PlayerDistance()); MoveAway(); } break; case RetreatState.COOLDOWN: anim.SetInteger("State", 1); myBase.myRigid.velocity = Vector2.zero; myBase.myStats.currentHP = myBase.myStats.maxHP; //wait until cooldown time is over if (OnTarget()) { retreatState = RetreatState.ACTIVATING; } break; } }
private void Awake() { prevFramePos = this.transform.position; chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); attackState = new AttackState(this); retreatState = new RetreatState(this); attackState.Start(); // note to self call start on states that it is needed navMeshAgent = GetComponent <NavMeshAgent>(); weaponSwingRenderer = GetComponent <LineRenderer>(); m_sphereCol = GetComponent <SphereCollider>(); m_animator = GetComponent <Animator>(); m_animator.applyRootMotion = true; }
private void Start() { currentState = new InitialState(this); actions = new IAction[0]; // playerChar = GameObject.FindGameObjectWithTag("Player"); initialState = new InitialState(this); advanceState = new AdvanceState(this); retreatState = new RetreatState(this); projectileState = new ProjectileState(this); antiAirState = new AntiAirState(this); aerialState = new AerialState(this); jumpState = new JumpState(this); aggression = 0.0f; jumpChance = 0; aerialChance = 0; dpChance = 0; projectileChance = 0; idleChance = 0; retreatChance = 0; advanceChance = 0; totalTime = 0; }