private void InitializeFSM()
    {
        // Create Minion FSM.
        fsm = new FSM <States>();
        IdleState <States>    idleState    = new IdleState <States>(fsm, this);
        SearchState <States>  searchState  = new SearchState <States>(fsm, this);
        FlockState <States>   flockState   = new FlockState <States>(fsm, this, _flockingEntity);
        PursuitState <States> pursuitState = new PursuitState <States>(fsm, this);
        FleeState <States>    fleeState    = new FleeState <States>(fsm, this);

        // [EVERYONE] Idle Transitions.
        idleState.AddTransition(States.FLOCKING, flockState);
        idleState.AddTransition(States.SEARCHING, searchState);
        idleState.AddTransition(States.PURSUIT, pursuitState);

        pursuitState.AddTransition(States.FLEE, fleeState);
        pursuitState.AddTransition(States.FLOCKING, flockState);
        pursuitState.AddTransition(States.IDLE, idleState);

        fleeState.AddTransition(States.IDLE, idleState);
        fleeState.AddTransition(States.PURSUIT, pursuitState);


        // [BOSS] Search Transitions.
        searchState.AddTransition(States.IDLE, idleState);
        searchState.AddTransition(States.PURSUIT, pursuitState);

        // [MINIONS] Flocking Transitions.
        flockState.AddTransition(States.IDLE, idleState);
        flockState.AddTransition(States.PURSUIT, pursuitState);

        fsm.SetInitState(idleState);
    }
示例#2
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Panic, FSMStateID.Fleeing);
        attack.AddTransition(Transition.TooCloseTooPlayer, FSMStateID.Evade);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        FleeState flee = new FleeState();

        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        EvadeState evade = new EvadeState();

        evade.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        evade.AddTransition(Transition.OutOfEvadingRange, FSMStateID.Patrolling);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(flee);
        AddFSMState(evade);
    }
示例#3
0
    private void MakeFSM()
    {
        WanderState wander = new WanderState();

        wander.AddTransition(Transition.SawPlayer, StateID.Flee);

        FleeState flee = new FleeState();

        flee.AddTransition(Transition.NoPlayer, StateID.Wander);

        fsm = new FSMSystem();

        fsm.AddState(wander);
        fsm.AddState(flee);
    }
    private void ConstructFSM()
    {
        pointList = GameObject.FindGameObjectsWithTag("WayPoint");
        //
        //Creating a wapoint transform array for each state
        //
        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //
        //Create States
        //
        HideState   hide   = new HideState(waypoints);
        AttackState attack = new AttackState(waypoints);


        //Create the Dead state
        DeadState dead = new DeadState(waypoints);
        //there are no transitions out of the dead state

        PatrolState patrol = new PatrolState(waypoints);
        FleeState   flee   = new FleeState(waypoints);

        //add transitions OUT of the attack state
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        if (AI1)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
            attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);
        }

        if (AI2)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }

        attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);

        //add transitions OUT of the hide state
        hide.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the patrol state
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the flee state
        if (AI1)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        }
        if (AI2)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }
        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //Add state to the state list
        if (AI1)
        {
            AddFSMState(patrol);
        }

        if (AI2)
        {
            AddFSMState(hide);
        }

        AddFSMState(attack);
        AddFSMState(dead);
    }