// Use this for initialization
    void Awake()
    {
        // This is where we build the tree
        BTNode root = new BTPrioritySelector();
        bt = new BehaviorTree(root);

            // Should we transform?
            // Decorator to make sure this never wins the priority selection
            BTNode transformCheckDec = root.AddChild(new BTDecAlwaysFail());
                // Do the actual check
                transformCheckDec.AddChild(new BTAction(delegate(){
                        if (state == PlayerState.Normal && Input.GetKeyDown(KeyCode.Space)) {
                            BecomeHulk();
                        }
                        return BTStatusCode.Success;
                    }));

            // Normal sequence
            BTNode normalSeq = root.AddChild(new BTSequence());
                // Are we in Normal mode?
                normalSeq.AddChild(new BTCondition(delegate(){ return state == PlayerState.Normal; })); // Anonymous methods are great for this!
                // Get input
                normalSeq.AddChild(new BTAction(GetInput));
                // Move player
                normalSeq.AddChild(new BTAction(NormalMove));

            // Hulk sequence
            BTNode hulkSeq = root.AddChild(new BTSequence());
                // Assume we're in hulk mode if we're here
                // Get input
                hulkSeq.AddChild(new BTAction(GetInput)); // New instance b/c each instance has it own status
                // Move player
                hulkSeq.AddChild(new BTAction(HulkMove));
    }
Esempio n. 2
0
    protected override void Init()
    {
        base.Init();
        m_DirectID = database.GetDataId("direct");
        database.SetData <Vector2>(m_DirectID, new Vector2(1, 0));

        m_timeWaitId = database.GetDataId("timeWait");
        database.SetData <float>(m_timeWaitId, 0);

        CheckPlayer      _checkPlayer      = new CheckPlayer(m_Find);
        CheckAllowAttack _checkAllowAttack = new CheckAllowAttack(m_timeWaitId, timeAttack);

        BTPrecondition2 con = new BTPrecondition2(_checkPlayer, _checkAllowAttack, BTPrecondition2.BTPrecondition2Param.And);

        _root = new BTPrioritySelector();
        BTParallel moveAttack = new BTParallel(BT.BTParallel.ParallelFunction.Or, con);
        float      maxX, maxY;

        maxX = distance.position.x - transform.position.x;
        maxY = 0;
        moveAttack.AddChild(new Move(speed, new Vector2(1, 0), transform.position, maxX, maxY, m_DirectID, null, true));
        moveAttack.AddChild(new Shoot(bulletObject, shooter, new Vector2(0, -1), m_timeWaitId));

        _root.AddChild(moveAttack);
        _root.AddChild(new Move(speed, new Vector2(1, 0), transform.position, maxX, maxY, m_DirectID, null, true));
    }
Esempio n. 3
0
    protected override void Init()
    {
        base.Init();
        m_DirectID = database.GetDataId("direct");
        database.SetData <Vector2>(m_DirectID, new Vector2(0, 0));
        CheckPlayer _checkPlayer = new CheckPlayer(m_Find, true);

        _root = new BTPrioritySelector();
        _root.AddChild(new Move(m_speed, new Vector2(0, 0), transform.position, 999, 999, m_DirectID, _checkPlayer));
    }
Esempio n. 4
0
    protected override void Init()
    {
        base.Init();
        CheckPlayer _checkPlayer = new CheckPlayer(m_Find, true);

        _root = new BTPrioritySelector();
        BTPrioritySelector selector = new BTPrioritySelector();

        selector.AddChild(new Move(m_Speed, new Vector2(-1, 0), transform.position, 10, 0, -1, _checkPlayer));
        selector.AddChild(new PlayAnimation("fly"));
        _root.AddChild(selector);
    }
Esempio n. 5
0
        public override void Init()
        {
            Debug.Log("S");
            _rootNode = new BTPrioritySelector(null);


            ValueCondition            vc    = new ValueCondition(10, true);
            ValueCondition            vd    = new ValueCondition(10, false);
            DieCondition              die   = new DieCondition();
            EnemyInSight              sight = new EnemyInSight();
            CheckSelfToTargetDistance CTD   = new CheckSelfToTargetDistance(vo.AttackDistance, false);
            CheckSelfToTargetDistance CTD2  = new CheckSelfToTargetDistance(vo.AttackDistance, true);

            AiTestAction1 first  = new AiTestAction1(vc);
            AiTestAction2 second = new AiTestAction2(vd);

            BTDieAction    dieAction    = new BTDieAction(3);
            BTPortalAction portalAction = new BTPortalAction();
            BTAttackAction attackAction = new BTAttackAction(vo.AttackCD);
            BTChaseAction  ChaseAction  = new BTChaseAction();



            BTParallel p = new BTParallel(die);

            _rootNode.AddChild(p);
            p.AddChild(dieAction);
            p.AddChild(new PlayAnimatorAction("Die"));

            BTPrioritySelector Select  = new BTPrioritySelector(null);
            BTPrioritySelector Select2 = new BTPrioritySelector(null);
            BTParallel         p2      = new BTParallel(ParallelFunction.And, sight);

            _rootNode.AddChild(Select);
            Select.AddChild(p2);
            p2.AddChild(portalAction);
            p2.AddChild(new PlayAnimatorAction("Run"));

            Select.AddChild(Select2);
            BTParallel p3 = new BTParallel(ParallelFunction.And, CTD);

            p3.AddChild(attackAction);
            p3.AddChild(new PlayAnimatorAction("attack1"));

            BTParallel p4 = new BTParallel(ParallelFunction.Or, null);

            p4.AddChild(ChaseAction);
            p4.AddChild(new PlayAnimatorAction("Run"));

            Select2.AddChild(p3);
            Select2.AddChild(p4);
        }
Esempio n. 6
0
    protected override void Init()
    {
        base.Init();
        m_DirectID = database.GetDataId("direct");
        database.SetData<Vector2>(m_DirectID, new Vector2(0, 0));
        CheckPlayer _checkPlayer = new CheckPlayer(m_Find);
        _root = new BTPrioritySelector();

        BTParallel run = new BTParallel(BTParallel.ParallelFunction.Or,_checkPlayer);
        run.AddChild(new Move(m_Speed, new Vector2(0, 0), transform.position, 999, 999, m_DirectID));
        run.AddChild(new PlayAnimation("run"));
        _root.AddChild(run);
        _root.AddChild(new PlayAnimation("stand"));

    }
Esempio n. 7
0
    protected override void Init()
    {
        base.Init();
        m_r2d = GetComponent <Rigidbody2D>();
        m_CheckCollisionId = database.GetDataId("checkCollision");
        database.SetData <bool>(m_CheckCollisionId, false);

        CheckPlayer    _checkPlayer    = new CheckPlayer(m_Find, true);
        CheckCollision _checkCollision = new CheckCollision(m_CheckCollisionId);

        _root = new BTPrioritySelector();
        _root.AddChild(new PlayAnimation("exploision", _checkCollision));
        _root.AddChild(new PlayAnimation("fall", _checkPlayer));
        _root.AddChild(new PlayAnimation("hang"));
    }
Esempio n. 8
0
    // Use this for initialization
    void Awake()
    {
        // This is where we build the tree
        BTNode root = new BTPrioritySelector();

        bt = new BehaviorTree(root);

        // Should we transform?
        // Decorator to make sure this never wins the priority selection
        BTNode transformCheckDec = root.AddChild(new BTDecAlwaysFail());

        // Do the actual check
        transformCheckDec.AddChild(new BTAction(delegate(){
            if (state == PlayerState.Normal && Input.GetKeyDown(KeyCode.Space))
            {
                BecomeHulk();
            }
            return(BTStatusCode.Success);
        }));

        // Normal sequence
        BTNode normalSeq = root.AddChild(new BTSequence());

        // Are we in Normal mode?
        normalSeq.AddChild(new BTCondition(delegate(){ return(state == PlayerState.Normal); }));                        // Anonymous methods are great for this!
        // Get input
        normalSeq.AddChild(new BTAction(GetInput));
        // Move player
        normalSeq.AddChild(new BTAction(NormalMove));

        // Hulk sequence
        BTNode hulkSeq = root.AddChild(new BTSequence());

        // Assume we're in hulk mode if we're here
        // Get input
        hulkSeq.AddChild(new BTAction(GetInput));                         // New instance b/c each instance has it own status
        // Move player
        hulkSeq.AddChild(new BTAction(HulkMove));
    }
Esempio n. 9
0
    protected override void Init()
    {
        base.Init();
        float time       = 0;
        float timeAttack = m_MaxTimeAttack + 1;

        m_timeWaitId = database.GetDataId("timeWait");
        database.SetData <float>(m_timeWaitId, time);

        m_timeAttackId = database.GetDataId("timeAttack");
        database.SetData <float>(m_timeAttackId, timeAttack);

        _root = new BTPrioritySelector();
        CheckPlayer      _checkPlayer      = new CheckPlayer(m_Find);
        CheckAllowAttack _checkAllowAttack = new CheckAllowAttack(m_timeWaitId, m_TimeAttackCooldown);
        CheckAttacking   _checkAttacking   = new CheckAttacking(m_timeAttackId, m_MaxTimeAttack);

        BTPrecondition2 con1 = new BTPrecondition2(_checkAllowAttack, _checkAttacking, BTPrecondition2.BTPrecondition2Param.Or);
        BTPrecondition2 con2 = new BTPrecondition2(_checkPlayer, con1, BTPrecondition2.BTPrecondition2Param.And);

        _root.AddChild(new PlayAnimation("attack", con2));
        _root.AddChild(new PlayAnimation("stand"));
    }
Esempio n. 10
0
    protected override void Init()
    {
        base.Init();
        float   time       = 0;
        float   timeAttack = m_MaxTimeAttack + 1;
        Vector2 direct     = new Vector2(0, 1);

        m_DirectID = database.GetDataId("direct");
        database.SetData <Vector2>(m_DirectID, direct);

        m_timeWaitId = database.GetDataId("timeWait");
        database.SetData <float>(m_timeWaitId, time);

        m_timeAttackId = database.GetDataId("timeAttack");
        database.SetData <float>(m_timeAttackId, timeAttack);

        _root = new BTPrioritySelector();
        CheckPlayer      _checkPlayer      = new CheckPlayer(m_Find);
        CheckAllowAttack _checkAllowAttack = new CheckAllowAttack(m_timeWaitId, m_TimeAttackCooldown);
        CheckAttacking   _checkAttacking   = new CheckAttacking(m_timeAttackId, m_MaxTimeAttack);

        BTPrecondition2 con1 = new BTPrecondition2(_checkAllowAttack, _checkAttacking, BTPrecondition2.BTPrecondition2Param.Or);
        BTPrecondition2 con2 = new BTPrecondition2(_checkPlayer, con1, BTPrecondition2.BTPrecondition2Param.And);

        BTParallel moveAttack = new BTParallel(BT.BTParallel.ParallelFunction.Or);

        moveAttack.AddChild(new Move(m_Speed, direct, transform.position, 1000f, 0.2f, m_DirectID));

        BTPrioritySelector fight = new BTPrioritySelector();

        fight.AddChild(new PlayAnimation("attack", con2));
        fight.AddChild(new PlayAnimation("fly"));

        moveAttack.AddChild(fight);
        _root.AddChild(moveAttack);
    }
Esempio n. 11
0
    protected override void Init()
    {
        // -------Prepare--------
        // 1. Initialize parent
        base.Init ();

        // 2. Enable BT framework's log for debug, optional
        // BTConfiguration.ENABLE_LOG = true;

        // 3. Create root, usually it's a priority selector
        _root = new BTPrioritySelector();

        // 4. Create the nodes for reuse later

        // Preconditions
        CheckInSight checkOrcInSight = new CheckInSight(sightForOrc, ORC_NAME);
        CheckInSight checkGoblinInFightDistance = new CheckInSight(fightDistance, GOBLIN_NAME);
        CheckInSight checkGoblinInSight = new CheckInSight(sightForGoblin, GOBLIN_NAME);

        // Actions
        BTParallel run = new BTParallel(BTParallel.ParallelFunction.Or);
        {
            run.AddChild(new DoRun(DESTINATION, speed));
            run.AddChild(new PlayAnimation(RUN_ANIMATION));
        }

        FindEscapeDestination findDestination = new FindEscapeDestination(ORC_NAME, DESTINATION, sightForOrc);
        FindToTargetDestination findToTargetDestination = new FindToTargetDestination(GOBLIN_NAME, DESTINATION, fightDistance * 0.9f);

        // -------Construct-------

        // 3.1 Escape node
        // "Escape" serves as a parallel node
        // "Or" means the parallel node ends when any of its children ends.
        BTParallel escape = new BTParallel(BTParallel.ParallelFunction.Or, checkOrcInSight);
        {
            escape.AddChild(findDestination);

            escape.AddChild(run);
        }
        _root.AddChild(escape);		// Add node into root

        // 3.2 Fight node

        BTSequence fight = new BTSequence(checkGoblinInSight);
        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findToTargetDestination);

                parallel.AddChild(run);		// Reuse Run
            }
            fight.AddChild(parallel);

            fight.AddChild(new PlayAnimation(FIGHT_ANIMATION, checkGoblinInFightDistance));
        }
        _root.AddChild(fight);

        // 3.3 Idle node
        _root.AddChild(new PlayAnimation(IDLE_ANIMATION));
    }
Esempio n. 12
0
    protected override void Init()
    {
        base.Init();
        root = new BTPrioritySelector();   // 根节点首先是一个选择器

        // 转移条件
        MonsterCheckPlayerInRange playerInRange    = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME);
        MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true);

        // 行为节点
        move = new MonsterMove(DESTINATION, moveSpeed);
        MonsterFindToTargetDestination findToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKdistance);
        MonsterWait monsterWait = new MonsterWait();

        // 怪兽攻击
        MonsterAttack monsterAttack;

        if (myMonsterType == MonsterType.LongDistanceAttack)
        {
            monsterAttack = new MonsterLongDistanceAttacks(longDistanceATK);
        }
        else if (myMonsterType == MonsterType.MeleeAttack)
        {
            monsterAttack = new MonsterMeleeAttack(meleeATK);
        }
        else
        {
            monsterAttack = new MonsterAttack(meleeATK);     // 先暂时为近战的攻击力
        }
        MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ);
        MonsterRotateToTarget     monsterMoveRotate  = new MonsterRotateToTarget(DESTINATION);
        MonsterRotateToTarget     attackRotate       = new MonsterRotateToTarget(PLAYERLOCATION);

        // 攻击
        BTSequence attack = new BTSequence(playerInRange);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            attack.AddChild(parallel);
            attack.AddChild(attackRotate);                // 怪物朝向玩家
            attack.AddChild(monsterAttack);               // 进行攻击
        }
        root.AddChild(attack);

        // 随机巡逻
        BTSequence randomMove = new BTSequence(playerNotInRange);

        {
            randomMove.AddChild(monsterWait);                  // 怪物静止几秒

            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And);
            {
                parallel.AddChild(randomMoveDistance);         // 随机找一个移动地点
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            randomMove.AddChild(parallel);
        }
        root.AddChild(randomMove);
    }
Esempio n. 13
0
    protected override void Init()
    {
        base.Init();
        root = new BTPrioritySelector();   // 根节点首先是一个选择器

        // 转移条件
        // 远程攻击条件
        MonsterCheckPlayerInRangeAndRandomAttack longAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, true);
        // 进程攻击条件
        MonsterCheckPlayerInRangeAndRandomAttack meleeAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, false);
        // 静止条件
        MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true);

        // 行为节点
        move = new MonsterMove(DESTINATION, moveSpeed);
        MonsterFindToTargetDestination findMeleeToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKMeleeDistance);
        MonsterFindToTargetDestination findLongToTargetDestination  = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKLongDistance);
        MonsterWait monsterWait = new MonsterWait();

        MonsterLongDistanceAttacks monsterLongDistanceAttacks = new MonsterLongDistanceAttacks(longDistanceATK);
        MonsterMeleeAttack         monsterMeleeAttack         = new MonsterMeleeAttack(meleeATK);

        MonsterRotateToTarget monsterMoveRotate = new MonsterRotateToTarget(DESTINATION);
        MonsterRotateToTarget attackRotate      = new MonsterRotateToTarget(PLAYERLOCATION);

        MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ);

        // 随机巡逻(玩家不在攻击范围)
        BTSequence randomMove = new BTSequence(playerNotInRange);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And);
            {
                parallel.AddChild(randomMoveDistance);         // 随机找一个移动地点
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            randomMove.AddChild(parallel);
        }
        root.AddChild(randomMove);

        // 进程攻击(一个随机数并且玩家在攻击范围内)
        BTSequence meleeattack = new BTSequence(meleeAttack);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findMeleeToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);                   // 怪物朝着目的地移动
            }
            meleeattack.AddChild(parallel);
            meleeattack.AddChild(attackRotate);                     // 怪物朝向玩家
            meleeattack.AddChild(monsterMeleeAttack);               // 进行攻击
        }
        root.AddChild(meleeattack);

        // 远程攻击(一个随机数并且玩家在攻击范围内)
        BTSequence longattack = new BTSequence(longAttack);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findLongToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);                   // 怪物朝着目的地移动
            }
            longattack.AddChild(parallel);
            longattack.AddChild(attackRotate);                          // 怪物朝向玩家
            longattack.AddChild(monsterLongDistanceAttacks);            // 进行攻击
        }
        root.AddChild(longattack);
    }
Esempio n. 14
0
    protected override void Init()
    {
        // -------Prepare--------
        // 1. Initialize parent
        base.Init();

        // 2. Enable BT framework's log for debug, optional
        // BTConfiguration.ENABLE_LOG = true;

        // 3. Create root, usually it's a priority selector
        _root = new BTPrioritySelector();

        // 4. Create the nodes for reuse later

        // Preconditions
        CheckInSight checkOrcInSight            = new CheckInSight(sightForOrc, ORC_NAME);
        CheckInSight checkGoblinInFightDistance = new CheckInSight(fightDistance, GOBLIN_NAME);
        CheckInSight checkGoblinInSight         = new CheckInSight(sightForGoblin, GOBLIN_NAME);

        // Actions
        BTParallel run = new BTParallel(BTParallel.ParallelFunction.Or);
        {
            run.AddChild(new DoRun(DESTINATION, speed));
            run.AddChild(new PlayAnimation(RUN_ANIMATION));
        }

        FindEscapeDestination   findDestination         = new FindEscapeDestination(ORC_NAME, DESTINATION, sightForOrc);
        FindToTargetDestination findToTargetDestination = new FindToTargetDestination(GOBLIN_NAME, DESTINATION, fightDistance * 0.9f);



        // -------Construct-------

        // 3.1 Escape node
        // "Escape" serves as a parallel node
        // "Or" means the parallel node ends when any of its children ends.
        BTParallel escape = new BTParallel(BTParallel.ParallelFunction.Or, checkOrcInSight);

        {
            escape.AddChild(findDestination);

            escape.AddChild(run);
        }
        _root.AddChild(escape);                 // Add node into root


        // 3.2 Fight node

        BTSequence fight = new BTSequence(checkGoblinInSight);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findToTargetDestination);

                parallel.AddChild(run);                         // Reuse Run
            }
            fight.AddChild(parallel);

            fight.AddChild(new PlayAnimation(FIGHT_ANIMATION, checkGoblinInFightDistance));
        }
        _root.AddChild(fight);


        // 3.3 Idle node
        _root.AddChild(new PlayAnimation(IDLE_ANIMATION));
    }
Esempio n. 15
0
    // Use this for initialization
    void Awake()
    {
        blackboard.Put("ChasingPlayer", false);

        // Begin the tree
        BTNode root = new BTPrioritySelector();
        bt = new BehaviorTree(root);

            // Player in Hulk mode branch
            BTNode hulkModeSeq = root.AddChild(new BTSequence());
                // Is the player in hulk mode?
                hulkModeSeq.AddChild(new BTCondition(delegate(){
                        if (target == null) return false;
                        else return target.GetComponent<BTChasePlayer>().state == BTChasePlayer.PlayerState.Hulk;
                    }));
                // Set "ChasingPlayer" to false in the blackboard
                hulkModeSeq.AddChild(new BTAction(delegate(){
                        blackboard.Put("ChasingPlayer", false);
                        return BTStatusCode.Success;
                    }));
                // Are we safe?
                BTNode botNotSafeSwitch = hulkModeSeq.AddChild(new BTSwitch());
                    // Are we far enough away yet?
                    botNotSafeSwitch.AddChild(new BTCondition(delegate(){
                            Vector3 dist = target.transform.position - transform.position;
                            if (dist.sqrMagnitude > runRadius * runRadius) return false;
                            else return true;
                        }));
                    // Yes, let's move away
                    botNotSafeSwitch.AddChild(new BTAction(MoveAway));
                    // No, let's idle
                    botNotSafeSwitch.AddChild(new BTDecAlwaysSucceed());

            // Player in Normal mode branch
            BTNode normalModeSeq = root.AddChild(new BTSequence());
                // Have we noticed the player?
                normalModeSeq.AddChild(new BTCondition(delegate(){
                        if (target == null) return false;
                        else if (blackboard.Look("ChasingPlayer") != null) {
                            return (bool)blackboard.Look("ChasingPlayer");
                        } else return false;
                    }));
                // Do we need to be moving closer still?
                BTNode botTooFarSwitch = normalModeSeq.AddChild(new BTSwitch());
                    // Are we still outside the minimum distance?
                    botTooFarSwitch.AddChild(new BTCondition(delegate(){
                            Vector3 dist = target.transform.position - transform.position;
                            if (dist.sqrMagnitude <= chaseRadius * chaseRadius) return false;
                            else return true;
                        }));
                    // Yes, move closer
                    botTooFarSwitch.AddChild(new BTAction(MoveTowards));
                    // No, let's idle
                    botTooFarSwitch.AddChild(new BTDecAlwaysSucceed());

            // Player in Idle mode branch
            BTNode idleModeSeq = root.AddChild(new BTSequence());
                // If the player is in range, start chasing
                idleModeSeq.AddChild(new BTAction(delegate(){
                        Vector3 dist = target.transform.position - transform.position;
                        if (dist.sqrMagnitude <= runRadius * runRadius) blackboard.Put("ChasingPlayer", true);
                        return BTStatusCode.Success;
                    }));
                // Idle
                idleModeSeq.AddChild(new BTDecAlwaysSucceed());
    }
Esempio n. 16
0
    private void Start()
    {
        BTBaseNode engage =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckTaskStatus(
                        new BTCheckRange(myAgent, targetPlayer, 15),
                        new BTSetBool(engaged, false),
                        new BTSetBool(Player.inCombat, false)
                        ),

                    new BTCheckBool(isArmed, false),

                    new BTCheckTaskStatus(
                        new BTInverter(new BTCheckRange(myAgent, targetWeapon, 1.5f)),
                        new BTSetBool(isArmed, true)
                        ),

                    new BTAnimate(animator, "Run"),
                    new BTMove(5, agentNavMesh, targetWeapon)
                    ),
                new BTSequence(
                    new BTCheckRange(myAgent, targetPlayer, 1),
                    new BTAnimate(animator, "Run"),
                    new BTMove(3, agentNavMesh, targetPlayer)
                    ),
                new BTSequence(
                    new BTStop(agentNavMesh),
                    new BTAnimate(animator, "Kick", "Idle")
                    )
                );

        engage._name = "Engage";

        BTBaseNode patrol =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(engaged, false),

                    new BTCheckTaskStatus(
                        new BTSpot(targetPlayer, myAgent, spotDistance, true),
                        new BTSetBool(Player.inCombat, true),
                        new BTSetBool(engaged, true)
                        ),

                    new BTCheckRange(myAgent, wayPoint, 1),
                    new BTAnimate(animator, "Rifle Walk"),
                    new BTMove(2, agentNavMesh, wayPoint)
                    ),
                new BTSequence(
                    new BTCheckBool(engaged, false),

                    new BTCheckTaskStatus(
                        new BTSpot(targetPlayer, myAgent, spotDistance, true),
                        new BTSetBool(Player.inCombat, true),
                        new BTSetBool(engaged, true)
                        ),

                    new BTAnimate(animator, "Idle"),
                    new BTWait(3),
                    new BTNextWaypoint(wayPoint, waypoints)// Get new Waypoint
                    ));

        patrol._name = "Patrol";

        BTBaseNode stunned =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(isStunned, true),
                    new BTAnimate(animator, "Scared"),
                    new BTStop(agentNavMesh),
                    new BTSetBool(Player.inCombat, false),

                    new BTCheckTaskStatus(
                        new BTWait(5),
                        new BTSetBool(engaged, false),
                        new BTSetBool(isStunned, false)

                        )
                    )
                );

        stunned._name = "Stunned";


        tree = new BTPrioritySelector(
            stunned,
            patrol,
            engage
            );
    }
Esempio n. 17
0
    // Use this for initialization
    void Awake()
    {
        blackboard.Put("ChasingPlayer", false);

        // Begin the tree
        BTNode root = new BTPrioritySelector();

        bt = new BehaviorTree(root);

        // Player in Hulk mode branch
        BTNode hulkModeSeq = root.AddChild(new BTSequence());

        // Is the player in hulk mode?
        hulkModeSeq.AddChild(new BTCondition(delegate(){
            if (target == null)
            {
                return(false);
            }
            else
            {
                return(target.GetComponent <BTChasePlayer>().state == BTChasePlayer.PlayerState.Hulk);
            }
        }));
        // Set "ChasingPlayer" to false in the blackboard
        hulkModeSeq.AddChild(new BTAction(delegate(){
            blackboard.Put("ChasingPlayer", false);
            return(BTStatusCode.Success);
        }));
        // Are we safe?
        BTNode botNotSafeSwitch = hulkModeSeq.AddChild(new BTSwitch());

        // Are we far enough away yet?
        botNotSafeSwitch.AddChild(new BTCondition(delegate(){
            Vector3 dist = target.transform.position - transform.position;
            if (dist.sqrMagnitude > runRadius * runRadius)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }));
        // Yes, let's move away
        botNotSafeSwitch.AddChild(new BTAction(MoveAway));
        // No, let's idle
        botNotSafeSwitch.AddChild(new BTDecAlwaysSucceed());

        // Player in Normal mode branch
        BTNode normalModeSeq = root.AddChild(new BTSequence());

        // Have we noticed the player?
        normalModeSeq.AddChild(new BTCondition(delegate(){
            if (target == null)
            {
                return(false);
            }
            else if (blackboard.Look("ChasingPlayer") != null)
            {
                return((bool)blackboard.Look("ChasingPlayer"));
            }
            else
            {
                return(false);
            }
        }));
        // Do we need to be moving closer still?
        BTNode botTooFarSwitch = normalModeSeq.AddChild(new BTSwitch());

        // Are we still outside the minimum distance?
        botTooFarSwitch.AddChild(new BTCondition(delegate(){
            Vector3 dist = target.transform.position - transform.position;
            if (dist.sqrMagnitude <= chaseRadius * chaseRadius)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }));
        // Yes, move closer
        botTooFarSwitch.AddChild(new BTAction(MoveTowards));
        // No, let's idle
        botTooFarSwitch.AddChild(new BTDecAlwaysSucceed());

        // Player in Idle mode branch
        BTNode idleModeSeq = root.AddChild(new BTSequence());

        // If the player is in range, start chasing
        idleModeSeq.AddChild(new BTAction(delegate(){
            Vector3 dist = target.transform.position - transform.position;
            if (dist.sqrMagnitude <= runRadius * runRadius)
            {
                blackboard.Put("ChasingPlayer", true);
            }
            return(BTStatusCode.Success);
        }));
        // Idle
        idleModeSeq.AddChild(new BTDecAlwaysSucceed());
    }
Esempio n. 18
0
    private void Start()
    {
        for (int i = 0; i < hideSpots.transform.childCount; i++)
        {
            VariableGameObject spot = Instantiate(hideSpot);
            spot.Value = hideSpots.transform.GetChild(i).gameObject;
            hideSpotCollection.Add(spot);
        }

        myAgent.Value   = this.gameObject;
        myPlayer.Value  = myPlayerObject;
        Target.Value    = myTarget;
        Enemy.Value     = myEnemy;
        moveSpeed.Value = 0;

        BTBaseNode follow =
            new BTPrioritySelector(
                new BTSequence(
                    new BTSetTarget(Target, myPlayer),
                    new BTCheckRange(myAgent, Target, 5),
                    new BTAnimate(animator, "Run"),
                    new BTMove(2.5f, myNavMesh, Target)
                    ),
                new BTSequence(
                    new BTCheckRange(myAgent, Target, 2),
                    new BTAnimate(animator, "Walk Crouch"),
                    new BTMove(2, myNavMesh, Target)
                    ),
                new BTSequence(
                    new BTAnimate(animator, "Crouch Idle"),
                    new BTStop(myNavMesh)
                    )
                );

        follow._name = "Follow";

        BTBaseNode hide =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, false),

                    new BTGetClosestHideSpot(hideSpotCollection, myAgent, Target, Enemy),
                    new BTCheckRange(myAgent, Target, 0.5f),

                    new BTAnimate(animator, "Run"),
                    new BTMove(2.5f, myNavMesh, Target)

                    ),
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, false),
                    new BTStop(myNavMesh),
                    new BTAnimate(animator, "Crouch Idle"),

                    new BTCheckTaskStatus(
                        new BTWait(3),
                        new BTSetBool(hidden, true)
                        )
                    ),
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, true),

                    new BTCheckTaskStatus(
                        new BTSpot(Enemy, myAgent, 200, false),
                        new BTSetBool(hidden, false)
                        ),

                    new BTCheckTaskStatus(
                        new BTCheckBool(Enemy.Value.GetComponent <Guard>().isStunned, false),
                        new BTAnimate(animator, "Throw", "Crouch Idle"),
                        new BTCheckTaskStatus(
                            new BTWait(4),
                            new BTSetBool(Enemy.Value.GetComponent <Guard>().isStunned, true),
                            new BTSetBool(hidden, false)
                            )
                        )
                    )
                );

        hide._name = "Hide";

        tree = new BTPrioritySelector(
            hide,
            follow
            );
        tree._name = "Tree";
    }