Example #1
0
    protected virtual void Awake()
    {
        locator  = GetComponent <BotLocator>();
        attacker = GetComponent <BotAttacker>();

        hitbox = GetComponent <Hitbox>();
        hitbox.onDamageTaken += OnDamageTaken;

        controller = GetComponent <Controller2D>();

        globalPatrolTargets = new Vector3[patrolTargets.Length];

        if (gravityDirection == Vector2.zero)
        {
            Debug.LogWarning("Gravity not setup corectly");
            return;
        }

        for (int i = 0; i < patrolTargets.Length; i++)
        {
            globalPatrolTargets[i] = patrolTargets[i] + transform.position;

            if (gravityDirection.y != 0)
            {
                minPatrolTarget = i == 0 || minPatrolTarget.x > globalPatrolTargets[i].x ? globalPatrolTargets[i] : minPatrolTarget;
                maxPatrolTarget = i == 0 || maxPatrolTarget.x < globalPatrolTargets[i].x ? globalPatrolTargets[i] : maxPatrolTarget;
            }
            else
            {
                minPatrolTarget = i == 0 || minPatrolTarget.y > globalPatrolTargets[i].y ? globalPatrolTargets[i] : minPatrolTarget;
                maxPatrolTarget = i == 0 || maxPatrolTarget.y < globalPatrolTargets[i].y ? globalPatrolTargets[i] : maxPatrolTarget;
            }
        }
    }
Example #2
0
    protected void Awake()
    {
        locator    = GetComponent <BotLocator>();
        attacker   = GetComponent <BotAttacker>();
        controller = GetComponent <Controller2D>();

        hitbox = GetComponent <Hitbox>();
        hitbox.onDamageTaken += OnDamageTaken;

        globalPatrolTargets = new Vector2[patrolTargets.Length];

        for (int i = 0; i < patrolTargets.Length; i++)
        {
            globalPatrolTargets[i] = patrolTargets[i] + (Vector2)transform.position;
        }

        CalculatePatrolBounds();
    }
Example #3
0
    protected virtual void Awake()
    {
        locator      = GetComponent <BotLocator>();
        navigator    = GetComponent <IBotNavigator>();
        ctrlCollider = GetComponent <Collider2D>();

        contact           = new ContactFilter2D();
        contact.layerMask = locator.enemyMask;

        agent = GetComponent <AttackAgent>();
        agent.onAttackStart    = OnAttackStart;
        agent.onAttackComplete = OnAttackComplete;

        if (agent != null)
        {
            agent.Init(locator.enemyMask, locator.obstacleMask);
        }
    }
Example #4
0
    public void Awake()
    {
        locator   = GetComponent <BotLocator>();
        navigator = GetComponent <IBotNavigator>();
        attacker  = GetComponent <BotAttacker>();

        stateDecision = new DecisionTree <BotStateMachine, State>
        {
            showDebugInfo = showDecisionPath,
            root          = new DecisionTree <BotStateMachine, State> .Node
            {
                Condition = bot => bot.currentState == State.None,
                positive  = new DecisionTree <BotStateMachine, State> .Node
                {
                    decision = State.Idle
                },
                negative = new DecisionTree <BotStateMachine, State> .Node
                {
                    Condition = bot => bot.locator.LocateEnemy() != null,
                    positive  = new DecisionTree <BotStateMachine, State> .Node
                    {
                        Condition = bot => bot.navigator.IsTargetOnPath(bot.locator.LocateEnemy().transform.position),
                        positive  = new DecisionTree <BotStateMachine, State> .Node
                        {
                            Condition = bot => bot.attacker.EnemyInAttackRange(),
                            positive  = new DecisionTree <BotStateMachine, State> .Node
                            {
                                decision = State.Attack
                            },
                            negative = new DecisionTree <BotStateMachine, State> .Node
                            {
                                decision = State.KeepAttackDistance
                            }
                        },
                        negative = new DecisionTree <BotStateMachine, State> .Node
                        {
                            decision = State.Patrol
                        }
                    },
                    negative = new DecisionTree <BotStateMachine, State> .Node
                    {
                        Condition = bot => bot.currentState == State.KeepAttackDistance || bot.currentState == State.Attack,
                        positive  = new DecisionTree <BotStateMachine, State> .Node
                        {
                            decision = State.Idle
                        },
                        negative = new DecisionTree <BotStateMachine, State> .Node
                        {
                            Condition = bot => bot.currentState == State.Idle,
                            positive  = new DecisionTree <BotStateMachine, State> .Node
                            {
                                Condition = bot => bot.idleTime > 0,
                                positive  = new DecisionTree <BotStateMachine, State> .Node
                                {
                                    decision = State.Idle
                                },
                                negative = new DecisionTree <BotStateMachine, State> .Node
                                {
                                    decision = State.Patrol
                                }
                            },
                            negative = new DecisionTree <BotStateMachine, State> .Node
                            {
                                Condition = bot => bot.currentState == State.Patrol,
                                positive  = new DecisionTree <BotStateMachine, State> .Node
                                {
                                    Condition = bot => bot.patrolTime > 0,
                                    positive  = new DecisionTree <BotStateMachine, State> .Node
                                    {
                                        decision = State.Patrol
                                    },
                                    negative = new DecisionTree <BotStateMachine, State> .Node
                                    {
                                        decision = State.Idle
                                    }
                                },
                                negative = new DecisionTree <BotStateMachine, State> .Node
                                {
                                    decision = State.Idle
                                }
                            }
                        }
                    }
                }
            }
        };
    }