Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        fsm                 = new FSM("AITest FSM Two");
        MoveLeftState       = fsm.AddState("MoveLeftState");
        MoveRightState      = fsm.AddState("MoveRightState");
        MoveLeftAction      = new MoveAction(MoveLeftState);
        MoveRightAction     = new MoveAction(MoveRightState);
        MoveLeftTextAction  = new TextAction(MoveLeftState);
        MoveRightTextAction = new TextAction(MoveRightState);

        //This adds the actions to the state and add state to it's transition map
        MoveLeftState.AddAction(MoveLeftTextAction);
        MoveLeftState.AddAction(MoveLeftAction);
        MoveRightState.AddAction(MoveRightTextAction);
        MoveRightState.AddAction(MoveRightAction);

        MoveLeftState.AddTransition("ToRight", MoveRightState);
        MoveRightState.AddTransition("ToLeft", MoveLeftState);

        //this initializes the actions
        MoveLeftTextAction.Init("AI Moving Left", 1f, "");
        MoveRightTextAction.Init("AI Moving Right", 1f, "");
        MoveLeftAction.Init(this.transform, new Vector3(1, 0, 0), new Vector3(-1, 0, 0), 1.0f, "ToRight");
        MoveRightAction.Init(this.transform, new Vector3(-1, 0, 0), new Vector3(1, 0, 0), 1.0f, "ToLeft");

        //Starts the FSM
        fsm.Start("MoveLeftState");
    }
Beispiel #2
0
    void Start()
    {
        fsm = new FSM("Tower AI");

        // Create AttackState
        attackState  = fsm.AddState("AttackState");
        attackAction = new Attack(gameObject, attackState);

        // Create IdleState
        idleState  = fsm.AddState("IdleState");
        idleAction = new Idle(gameObject, idleState);

        // Add actions
        attackState.AddAction(attackAction);
        idleState.AddAction(idleAction);

        // Add events
        attackState.AddEvent("ToIdle", idleState);
        idleState.AddEvent("ToAttack", attackState);

        // Initialize actions
        attackAction.Start(finishEvent: "ToIdle");
        idleAction.Start(finishEvent: "ToAttack");

        // Start the fsm
        fsm.Start("IdleState");
    }
Beispiel #3
0
    private void Start()
    {
        fsm = new FSM("AITest FSM Two");
        MoveForwardState = fsm.AddState("MoveForwardState");
        IdleState        = fsm.AddState("MoveRightState");
        TurnState        = fsm.AddState("TurnState");

        MoveForwardAction = new MoveAction(MoveForwardState);
        IdleAction        = new MoveAction(IdleState);
        TurnAction        = new TurnAction(TurnState);

        MoveForwardState.AddAction(MoveForwardAction);
        IdleState.AddAction(IdleAction);
        TurnState.AddAction(TurnAction);

        MoveForwardState.AddTransition("ToTurn", TurnState);

        TurnState.AddTransition("ToIdle", IdleState);
        TurnState.AddTransition("ToTurn", TurnState);

        IdleState.AddTransition("ToForward", MoveForwardState);
        IdleState.AddTransition("ToTurn", TurnState);


        MoveForwardAction.Init(this.transform, .1f, 2.0f, "ToTurn");
        TurnAction.Init(this.transform, 2.0f, "ToIdle");
        IdleAction.Init(this.transform, 0, 2.0f, "ToForward");

        fsm.Start("MoveForwardState");
    }
Beispiel #4
0
    // Use this for initialization
    void Start()
    {
        m_fsm = new FSM();
        FSMState  state1  = new FSMState("log", m_fsm, true);
        LogAction action1 = new LogAction();

        action1.SetOwner(state1);
        state1.AddAction(action1);
        state1.AddTransition("calc", 2);

        FSMState   state2  = new FSMState("calc", m_fsm);
        CalcAction action2 = new CalcAction();

        action2.SetOwner(state2);
        state2.AddAction(action2);
        state2.AddTransition("log", state1.id);

        m_fsm.AddTransition("g_calc", state2.id);
        m_fsm.AddTransition("g_log", state1.id);

        m_fsm.AddState(state1);
        m_fsm.AddState(state2);

        m_fsm.Initialize();
        m_fsm.EnableFSM();

        StartCoroutine(SendGlobalEvent());
    }
Beispiel #5
0
        private void Start()
        {
            fsm          = new FiniteStateMachine("AITest FSM");
            IdleState    = fsm.AddState("IdleState");
            ScanState    = fsm.AddState("ScanState");
            PatrolState  = fsm.AddState("WanderState");
            PatrolAction = new WanderAction(PatrolState);
            IdleAction   = new IdleAction(IdleState);
            ScanAction   = new ScanningAction(ScanState);
            deathState   = fsm.AddState("DeathState");
            DeathAction  = new DeathState(deathState);
            //This adds the actions to the state and add state to it's transition map
            PatrolState.AddAction(PatrolAction);
            IdleState.AddAction(IdleAction);

            PatrolState.AddTransition("ToIdle", IdleState);
            IdleState.AddTransition("ToPatrol", PatrolState);
            ScanState.AddTransition("ToScanning", ScanState);
            deathState.AddTransition("ToDeath", deathState);
            PatrolAction.Init(target, 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToIdle");
            IdleAction.Init(target, "AI on Idle", 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToPatrol");
            DeathAction.Init(3.0f, gameObject.GetComponent <EnemyAstar>());
            ScanAction.Init(3.0f);
            fsm.StartMachine("IdleState");
        }
    // Use this for initialization
    void Start()
    {
        fsm           = new Core.FSM.FSM("PatrolDialogueNPCFSM");
        moveState     = fsm.AddState("MoveState");
        idleState     = fsm.AddState("IdleState");
        dialogueState = fsm.AddState("DialogueState");

        moveAction     = new WaypointMoveAction(moveState);
        idleAction     = new NPCIdleScoutAction(idleState);
        dialogueAction = new NPCDialogueAction(dialogueState);


        moveState.AddAction(moveAction);
        idleState.AddAction(idleAction);
        dialogueState.AddAction(dialogueAction);

        moveAction.Init(GetComponent <Rigidbody>(), gameObject.transform, movementSpeed, waypoints, "ToIdle");
        idleAction.Init(3, gameObject.transform);
        dialogueAction.Init(this, dialogueIdentifier);

        idleState.AddTransition("ToDialogue", dialogueState);
        idleState.AddTransition("ToNextWaypoint", moveState);

        moveState.AddTransition("ToIdle", idleState);
        dialogueState.AddTransition("ToIdle", idleState);

        fsm.Start("MoveState");
    }
    // Start is called before the first frame update
    void Awake()
    {
        damage       = enemyPreset.damage;
        moveTime     = enemyPreset.moveTime;
        idleTimeMin  = enemyPreset.idleTimeMin;
        idleTimeMax  = enemyPreset.idleTimeMax;
        wanderRadius = enemyPreset.wanderRadius;

        home = transform.position;

        trigger = GetComponentInChildren <DetectPlayer>();

        trigger.GetComponent <SphereCollider>().radius = enemyPreset.detectionRadius;

        navMeshAgent = GetComponent <NavMeshAgent>();

        navMeshAgent.speed = enemyPreset.speed;

        fsm = new FSM("MeleeAI FSM");

        WanderState = fsm.AddState("WanderState");
        IdleState   = fsm.AddState("IdleState");
        AlertState  = fsm.AddState("AlertState");
        MeleeState  = fsm.AddState("MeleeState");

        WanderAction = new WanderAction(WanderState);
        IdleAction   = new TextAction(IdleState);
        alertAction  = new AlertAction(AlertState);
        meleeAction  = new MeleeAction(MeleeState);

        WanderState.AddAction(WanderAction);
        IdleState.AddAction(IdleAction);
        AlertState.AddAction(alertAction);
        MeleeState.AddAction(meleeAction);

        WanderState.AddTransition("ToIdle", IdleState);
        WanderState.AddTransition("PlayerDetect", AlertState);
        IdleState.AddTransition("ToWander", WanderState);
        IdleState.AddTransition("PlayerDetect", AlertState);

        AlertState.AddTransition("ToIdle", IdleState);
        AlertState.AddTransition("ToMelee", MeleeState);
        MeleeState.AddTransition("ToAlert", AlertState);

        WanderAction.Init(this.transform, home, navMeshAgent, wanderRadius, moveTime, "ToIdle");
        IdleAction.Init("Idling", Random.Range(idleTimeMin, idleTimeMax), "ToWander");

        alertAction.Init(trigger, navMeshAgent, "ToIdle");
        meleeAction.Init(this.transform, damage, trigger, FindObjectOfType <PlayerManager>(), "ToAlert");

        fsm.Start("IdleState");
    }
    // Use this for initialization
    void Start()
    {
        player        = GameObject.FindGameObjectWithTag("Players");
        monsterAnim   = monsterObject.GetComponent <Animation> ();
        monsterWander = GetComponent <MonsterWandering> ();


        //FiniteStateMachine for Monsters
        fsm = new FSM("Monsters-FSM-AI");
        //define State and Action
        idleState    = fsm.AddState("IdleState");
        idleAction   = new actionIdle(idleState);
        wanderState  = fsm.AddState("WanderState");
        wanderAction = new actionWander(wanderState);
        chaseState   = fsm.AddState("ChaseState");
        chaseAction  = new actionChase(chaseState);
        backState    = fsm.AddState("BackState");
        backAction   = new actionBack(backState);
        sleepState   = fsm.AddState("SleepState");
        sleepAction  = new actionSleep(sleepState);

        //Add Action to State
        idleState.AddAction(idleAction);
        wanderState.AddAction(wanderAction);
        chaseState.AddAction(chaseAction);
        backState.AddAction(backAction);
        sleepState.AddAction(sleepAction);


        //Add Transation
        idleState.AddTransition("ToWander", wanderState);
        idleState.AddTransition("ToSleep", sleepState);
        wanderState.AddTransition("ToBack", backState);
        wanderState.AddTransition("ToChase", chaseState);
        chaseState.AddTransition("ToWander", wanderState);
        backState.AddTransition("ToSleep", sleepState);
        sleepState.AddTransition("ToIdle", idleState);

        //Init Action
        wanderAction.Init(gameObject, player, monsterAnim, monsterWander, "ToChase");
        idleAction.Init(gameObject, player, monsterAnim, monsterWander, "ToWander");
        chaseAction.Init(gameObject, player, monsterAnim, monsterWander, "ToWander");
        backAction.Init(gameObject, player, monsterAnim, monsterWander, "ToSleep");
        sleepAction.Init(gameObject, player, monsterAnim, monsterWander, "ToIdle");

        //Start
        fsm.Start("SleepState");
    }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        fsm        = new Core.FSM.FSM("PatrolNPCFSM");
        moveState  = fsm.AddState("MoveState");
        idleState  = fsm.AddState("IdleState");
        moveAction = new WaypointMoveAction(moveState);
        idleAction = new NPCIdleAction(idleState);

        moveState.AddAction(moveAction);
        idleState.AddAction(idleAction);

        moveAction.Init(GetComponent <Rigidbody>(), gameObject.transform, movementSpeed, waypoints, "ToIdle");
        idleAction.Init();

        idleState.AddTransition("ToNextWaypoint", moveState);
        moveState.AddTransition("ToIdle", idleState);

        fsm.Start("IdleState");
    }
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        IdleState    = fsm.AddState("IdleState");
        PatrolState  = fsm.AddState("PatrolState");
        PatrolAction = new TextAction(PatrolState);
        IdleAction   = new TextAction(IdleState);

        PatrolState.AddAction(PatrolAction);
        IdleState.AddAction(IdleAction);

        PatrolState.AddTransition("ToIdle", IdleState);
        IdleState.AddTransition("ToPatrol", PatrolState);

        PatrolAction.Init("AI on patrol", 3f, "ToIdle");
        IdleAction.Init("AI on idle", 2f, "ToPatrol");

        fsm.Start("IdleState");
    }
Beispiel #11
0
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        idleState    = fsm.AddState("IdleState");
        patrolState  = fsm.AddState("PatrolState");
        idleAction   = new TextAction(idleState);
        patrolAction = new TextAction(patrolState);

        //This adds the actions to the state and add state to it's transition map
        patrolState.AddAction(patrolAction);
        idleState.AddAction(idleAction);

        patrolState.AddTransition("ToIdle", idleState);
        idleState.AddTransition("ToPatrol", patrolState);

        patrolAction.Init("AI on Patrol", 3.0f, "ToIdle");
        idleAction.Init("AI on Idle", 2.0f, "ToPatrol");

        fsm.Start("IdleState");
    }
Beispiel #12
0
    private void Start()
    {
        fsm         = new FSM("Cub AI");
        FleeState   = fsm.AddState("FleeState");
        FollowState = fsm.AddState("FollowState");

        FleeAction   = new FleeAction(FleeState);
        FollowAction = new FollowAction(FollowState);

        FollowState.AddAction(FollowAction);
        FleeState.AddAction(FleeAction);

        FollowState.AddTransition("ToFlee", FleeState);
        FleeState.AddTransition("ToFollow", FollowState);

        FollowAction.Init(this.transform, .1f, gameObject);
        FleeAction.Init(this.transform, .1f, gameObject);

        fsm.Start("FollowState");
    }
    // Start is called before the first frame update
    void Start()
    {
        fsm         = new FSM("Test Ai");
        testState1  = fsm.AddState("testState1");
        testState2  = fsm.AddState("testState2");
        testState3  = fsm.AddState("testState3");
        testAction1 = new TestAction1(testState1);
        testAction2 = new TestAction1(testState2);
        testAction3 = new TestAction1(testState3);

        finishEvent1 = new List <string>
        {
            "To 2",
            "To 3"
        };
        finishEvent2 = new List <string>
        {
            "To 1",
        };
        finishEvent3 = new List <string>
        {
            "To 1",
        };

        testState1.AddAction(testAction1);
        testState2.AddAction(testAction2);
        testState3.AddAction(testAction3);


        testState1.AddTransition("To 2", testState2);
        testState1.AddTransition("To 3", testState3);

        testState2.AddTransition("To 1", testState1);
        testState3.AddTransition("To 1", testState1);

        testAction1.init("test 1", 1f, finishEvent1);
        testAction2.init("test 2", 1f, finishEvent2);
        testAction3.init("test 3", 1f, finishEvent3);
        fsm.Start("testState1");
    }
    // Use this for initialization
    void Start()
    {
        fsm        = new Core.FSM.FSM("PlayerFSM");
        moveState  = fsm.AddState("MoveState");
        idleState  = fsm.AddState("IdleState");
        moveAction = new MoveAction(moveState);
        idleAction = new IdleAction(idleState);

        moveState.AddAction(moveAction);
        idleState.AddAction(idleAction);

        PlayerRB  = gameObject.GetComponent <Rigidbody>();
        playerObj = GameObject.Find("Player");

        moveAction.Init(gameObject.transform, PlayerRB, velocity, sprintVelocity, jumpSpeed, "ToIdle");
        idleAction.Init();

        idleState.AddTransition("ToMove", moveState);
        moveState.AddTransition("ToIdle", idleState);

        fsm.Start("IdleState");
    }
Beispiel #15
0
    // Start is called before the first frame update
    void Start()
    {
        fsm             = new FSM("Ennemis");
        moveRightState  = fsm.AddState("moveRight");
        moveLeftState   = fsm.AddState("moveLeft");
        testState3      = fsm.AddState("testState3");
        moveRightAction = new MoveAction(moveRightState);
        moveLeftAction  = new MoveAction(moveLeftState);



        finishEvent2 = new List <string>
        {
            "To move right",
            //"To move left",
        };
        finishEvent3 = new List <string>
        {
            "To move left",
            //"To move right",
        };

        moveRightState.AddAction(moveRightAction);
        moveLeftState.AddAction(moveLeftAction);


        moveRightState.AddTransition("To move left", moveLeftState);
        moveLeftState.AddTransition("To move right", moveRightState);

        vecPos   = this.transform.position;
        vecRight = new Vector3(0.05f, 0, 0);
        vecLeft  = new Vector3(-0.05f, 0, 0);


        moveLeftAction.init(this.transform, vecPos, vecLeft, 1.5f, finishEvent2);
        moveRightAction.init(this.transform, vecPos, vecRight, 1.5f, finishEvent3);
        fsm.Start("moveLeft");
    }
    // Start is called before the first frame update
    void Start()
    {
        fsm             = new FSM("Test Ai 2");
        moveRightState  = fsm.AddState("moveRight");
        moveLeftState   = fsm.AddState("moveLeft");
        testState3      = fsm.AddState("testState3");
        moveRightAction = new MoveAction(moveRightState);
        moveLeftAction  = new MoveAction(moveLeftState);



        finishEvent2 = new List <string>
        {
            "To move right",
            //"To move left",
        };
        finishEvent3 = new List <string>
        {
            "To move left",
            //"To move right",
        };

        moveRightState.AddAction(moveRightAction);
        moveLeftState.AddAction(moveLeftAction);


        moveRightState.AddTransition("To move left", moveLeftState);
        moveLeftState.AddTransition("To move right", moveRightState);

        vecPos   = GameObject.Find("AI").transform.position;
        vecRight = new Vector3(0.4f, 0, 0);
        vecLeft  = new Vector3(-0.3f, 0, 0);


        moveLeftAction.init(this.transform, vecPos, vecLeft, 2.0f, finishEvent2);
        moveRightAction.init(this.transform, vecPos, vecRight, 2.0f, finishEvent3);
        fsm.Start("moveLeft");
    }
    void Start()
    {
        fsm = new FSM("Boss Ai");

        standState      = fsm.AddState("StandState");
        moveTargetState = fsm.AddState("MoveTargetState");
        retreatState    = fsm.AddState("RetreatState");
        runTargetState  = fsm.AddState("RunTargetState");
        jumpState       = fsm.AddState("JumpState");


        standAction      = new StandAction(standState);
        moveTargetAction = new MoveTargetAction(moveTargetState);
        retreatAction    = new RetreatAction(retreatState);
        runTargetAction  = new MoveTargetAction(runTargetState);
        jumpAction       = new JumpAction(jumpState);


        finishEventRun = new List <string>
        {
            "to move target",
            "to retreat",
            "to stand",
            "to jump"
        };

        finishEventStand = new List <string>
        {
            "to move target",
            "to retreat",
            "to run",
            "to jump"
        };

        finishEventMoveTarget = new List <string>
        {
            "to move target",
            "to stand",
            "to retreat",
            "to jump"
        };
        finishEventRetreat = new List <string>
        {
            "to stand",
            "to run"
        };
        finishEventJump = new List <string>
        {
            "to stand"
        };


        standState.AddAction(standAction);

        runTargetState.AddAction(runTargetAction);

        moveTargetState.AddAction(moveTargetAction);

        retreatState.AddAction(retreatAction);

        jumpState.AddAction(jumpAction);

        standState.AddTransition("to move target", moveTargetState);
        standState.AddTransition("to retreat", retreatState);
        standState.AddTransition("to run", runTargetState);
        standState.AddTransition("to jump", jumpState);

        moveTargetState.AddTransition("to move target", moveTargetState);
        moveTargetState.AddTransition("to stand", standState);
        moveTargetState.AddTransition("to retreat", retreatState);
        moveTargetState.AddTransition("to jump", jumpState);

        retreatState.AddTransition("to stand", standState);
        retreatState.AddTransition("to run", runTargetState);

        runTargetState.AddTransition("to move target", moveTargetState);
        runTargetState.AddTransition("to stand", standState);
        runTargetState.AddTransition("to retreat", retreatState);
        runTargetState.AddTransition("to jump", jumpState);

        jumpState.AddTransition("to stand", standState);



        vecPos     = GameObject.Find("Boss").transform.position;
        vecEnnemis = new Vector3(0.1f, 0, 0);
        vecJump    = new Vector3(0f, 0.15f, 0);


        moveTargetAction.init(this.transform, vecEnnemis, 2.0f, finishEventMoveTarget);
        retreatAction.init(this.transform, vecEnnemis, 0.5f, finishEventRetreat);
        runTargetAction.init(this.transform, new Vector3(0.3f, 0, 0), 1.0f, finishEventRun);
        jumpAction.init(this.transform, vecJump, 2f, finishEventJump);

        standAction.init(1.0f, finishEventStand);

        fsm.Start("StandState");
    }