Ejemplo n.º 1
0
    void Awake()
    {
        chaseState   = new ChaseState(this);
        alertState   = new AlertState(this);
        roamState    = new RoamState(this);
        neutralState = new NeutralState(this);
        passiveState = new PassiveState(this);

        m_Nav = GetComponent <NavMeshAgent>();
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        timer -= Time.deltaTime;

        switch (state)
        {
        case (RoamState.MOVE):
            Vector2 diff = target - (Vector2)transform.position;
            if (diff.magnitude < 0.2F)
            {
                target = new Vector2(Random.Range(xRange.x, xRange.y), Random.Range(yRange.x, yRange.y));
            }
            else
            {
                transform.Translate(diff.normalized * speed * Time.deltaTime);
            }
            if (timer < 0)
            {
                timer = shootTime;
                state = RoamState.SHOOT;
            }
            break;

        case (RoamState.SHOOT):
            if (timer < 0)
            {
                Vector2 dir = Random.insideUnitCircle;

                for (int i = 0; i < 4; i++)
                {
                    GameObject go = GameObject.Instantiate(bullet, transform.position, Quaternion.identity, null);
                    Bullet     b  = go.GetComponent <Bullet>();
                    b.SetDirection(dir);

                    dir = new Vector2(-dir.y, dir.x);
                }

                timer = waitTime;
                state = RoamState.WAIT;
            }
            break;

        case (RoamState.WAIT):
            if (timer < 0)
            {
                timer = roamTime;
                state = RoamState.MOVE;
            }
            break;
        }
    }
Ejemplo n.º 3
0
 public ThinkRoamAround(Vector2 anchor, float roamingRadius, float attackRange = 60, float sightRange = 110, float damage = 10f, bool canBeAttacked = true)
     : base()
 {
     _canBeAttacked = canBeAttacked;
     _goTo = new GoToPosition(.5f);
     _swing = new SwingHitAbility(1500, 0f, attackRange, damage);
     _rand = new Random();
     _anchor = anchor;
     _radius = roamingRadius;
     _state = RoamState.Idle;
     SightRange = sightRange;
 }
Ejemplo n.º 4
0
    void Awake()
    {
        // state references.
        rsState = GetComponent <RoamState>();
        chState = GetComponent <CollectHealthState>();
        sState  = GetComponent <ShootState>();
        caState = GetComponent <CollectAmmoState>();

        // initialize states.
        rsState.enabled = true;
        activeState     = rsState;
    }
Ejemplo n.º 5
0
    void Awake()
    {
        // state references.
        rs  = GetComponent <RoamState>();
        cs  = GetComponent <CollectHealthState>();
        ss  = GetComponent <ShootState>();
        ams = GetComponent <CollectAmmoState>();

        // initialize states.
        rs.enabled  = true;
        cs.enabled  = false;
        activeState = rs;
    }
Ejemplo n.º 6
0
    private void BuildFSM() //Crea los estados, y las trancisiones que llevan a otros estados.
    {
        IdleState idle = new IdleState(this);

        idle.AddTransition(TransitionID.StartRoaming, StateID.Roaming);
        idle.AddTransition(TransitionID.SawTarget, StateID.ChasingTarget);
        idle.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        idle.AddTransition(TransitionID.Dying, StateID.Dead);

        RoamState roam = new RoamState(this);

        roam.AddTransition(TransitionID.SawTarget, StateID.ChasingTarget);
        roam.AddTransition(TransitionID.StopRoaming, StateID.Idle);
        roam.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        roam.AddTransition(TransitionID.Dying, StateID.Dead);

        ChaseTargetState chaseTarget = new ChaseTargetState(this);

        chaseTarget.AddTransition(TransitionID.LostTarget, StateID.Roaming);
        chaseTarget.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        chaseTarget.AddTransition(TransitionID.InRange, StateID.Attack);
        chaseTarget.AddTransition(TransitionID.Dying, StateID.Dead);

        AttackState attack = new AttackState(this);

        attack.AddTransition(TransitionID.OutRange, StateID.ChasingTarget);
        attack.AddTransition(TransitionID.Dying, StateID.Dead);

        HurtState hurt = new HurtState(this);

        hurt.AddTransition(TransitionID.StopHurt, StateID.ChasingTarget);
        hurt.AddTransition(TransitionID.Dying, StateID.Dead);

        DeadState dead = new DeadState(this);

        dead.AddTransition(TransitionID.Healed, StateID.ChasingTarget);

        fsm = new FSM();
        fsm.AddState(roam);
        fsm.AddState(idle);
        fsm.AddState(chaseTarget);
        fsm.AddState(attack);
        fsm.AddState(hurt);
        fsm.AddState(dead);
    }
Ejemplo n.º 7
0
        private void CheckForTarget()
        {
            _lastState = _state;

            if ((Player.Instance.Position - _owner.Position).LengthSquared() < SightRange * SightRange)
            {
                _state = RoamState.Aggro;
            }
            else
            {
                _state = RoamState.Idle;
            }
        }