Exemplo n.º 1
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target == null)
            {
                return;
            }
            if (target.IsDead())
            {
                return;
            }

            bool isInRange = Vector3.Distance(transform.position, target.transform.position) < currentWeapon.value.GetRange();

            if (!isInRange)
            {
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 2
0
        private void Update()
        {
            m_TimeSinceLastAttack += Time.deltaTime;
            if (m_Target == null || m_Target.IsDead || attackDisabled)
            {
                return;
            }

            if (CombatTargetChanged(m_Target))
            {
                StopAttack();
            }

            if (!GetIsInRange(m_Target.transform))
            {
                m_Mover.MoveTo(m_Target.transform.position, 1f);
                m_Stopped = false;
            }
            else
            {
                if (!m_Stopped)
                {
                    m_Mover.Cancel();
                    m_Stopped = true;
                }

                AttackBehaviour();
            }
        }
Exemplo n.º 3
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;
            if (!target)
            {
                return;
            }
            // if (target.IsDead())

            if (!mover.NavMeshAgent.isStopped)
            {
                animator.ResetTrigger("attack");
                animator.SetTrigger("stopAttack");
            }

            if (target.IsDead())
            {
                animator.SetTrigger("stopAttack");
                return;
            }

            if (!GetIsInRange())
            {
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target == null)
            {
                return;
            }
            Health targetHealth = target.GetComponent <Health>();

            if (targetHealth != null && targetHealth.IsDead)
            {
                return;
            }

            if (!GetIsInRange())
            {
                _moverComponent.MoveTo(target.transform.position, 1f);
            }
            else
            {
                _moverComponent.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 5
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target == null)
            {
                return;
            }

            if (target.IsDead())
            {
                return;
            }

            if (!GetIsInRange())
            {
                mover.MoveTo(target.transform.position, 1f
                             );
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 6
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target == null)
            {
                return;
            }

            if (target.IsDead())
            {
                return;
            }

            // ensure there is already a target
            if (target != null && !IsInRange())
            {
                // move until in weapon range
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                // in weapon range, stop moving
                mover.Cancel();
                AttackBehavior();
            }
        }
Exemplo n.º 7
0
 void AttackBehaviour()
 {
     animator.SetTrigger("attack");
     moveController.Cancel();
     timeSinceLastAttack = 0f;
     transform.LookAt(target.transform);
 }
Exemplo n.º 8
0
        private void Update()
        {
            m_timeSinceLastAttack += Time.deltaTime;

            // No target exists
            if (m_target == null)
            {
                return;
            }

            // Target is already dead
            if (m_target.IsDead)
            {
                return;
            }

            // Get in range of the target
            if (m_target != null && !GetIsInRange(m_target.transform, m_currentWeaponConfig.WeaponRange))
            {
                m_mover.MoveTo(m_target.transform.position, 1f);
            }
            else
            {
                // Attack the target when in range
                m_mover.Cancel();
                AttackBehavior();
            }
        }
        private void GettingToTarget()
        {
            timeSinceLastAttack += Time.deltaTime;
            timeFromLastAttack  += Time.deltaTime;

            if (targetHealth == null)
            {
                return;
            }
            if (targetHealth.IsDead())
            {
                return;
            }


            if (Vector3.Distance(transform.position, targetHealth.transform.position) > currentWeaponConfig.Range)
            {
                mover.MoveTo(targetHealth.transform.position);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 10
0
        // Update is called once per frame
        void Update()
        {
            //updat Time since last attack
            m_timeSinceLastAttack += Time.deltaTime;


            if (m_Target == null)
            {
                return;
            }

            if (m_Target.GetIsDead())
            {
                return;
            }
            bool isInRange = Vector3.Distance(transform.position, m_Target.transform.position) < m_WeaponRange;

            Mover mover = GetComponent <Mover>();

            //move to target
            if (!isInRange)
            {
                mover.MoveTo(m_Target.transform.position);
            }
            else
            {
                mover.Cancel();
                AttackBehavior();
            }
        }
Exemplo n.º 11
0
        private void Update()
        {
            Health health = GetComponent <Health>();

            if (health == null || !health.Alive)
            {
                return;
            }
            timeSinceLastAttack += Time.deltaTime;

            if (target == null)
            {
                return;
            }
            if (GetIsInRange())
            {
                mover.Cancel();
                transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target.position - transform.position, Vector3.up), attackRotationSpeed);
                if (timeSinceLastAttack > currentWeapon.GetTimeBetweenAttacks())
                {
                    AttackBehavoiur();
                    timeSinceLastAttack = 0f;
                }
            }
            else
            {
                mover.MoveTo(target.position, 1f);
            }
        }
Exemplo n.º 12
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            /* This script only works after having an attack attackTarget
             * and this attackTarget is not dead.
             */
            if (!attackTarget || attackTarget.IsDead())
            {
                return;
            }
            if (!GetIsInRange())
            {
                /* If character is too far from attackTarget,
                 * it should move to the attackTarget at first.
                 */
                mover.MoveTo(attackTarget.transform.position, 1f);
            }
            else
            {
                // Stop move and do attack behaviour.
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 13
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;
            if (target == null)
            {
                return;
            }

            if (target.IsDead())
            {
                target = null;
                return;
            }

            if (!GetInRange())
            {
                // we want to move towards it probs
                mover.MoveTo(target.transform.position);
            }
            else
            {
                mover.Cancel();
                AttackBehavior();
            }
        }
Exemplo n.º 14
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target == null || target.IsDead())
            {
                return;
            }
            if (!currentWeapon.value)
            {
                return;
            }

            if (Vector3.Distance(transform.position, target.transform.position) > currentWeapon.value.GetWeaponRange())
            {
                moveComponent.MoveTo(target.transform.position);
            }
            else
            {
                moveComponent.Cancel();
                if (timeSinceLastAttack >= timeBetweenAttacks)
                {
                    AttackBehaviour();
                    timeSinceLastAttack = 0;
                }
            }
        }
Exemplo n.º 15
0
        void Update()
        {
            _timeSinceLastSawPlayer += Time.deltaTime;
            _timeSinceLastPatrolled += Time.deltaTime;
            _timeSinceAggravated    += Time.deltaTime;

            if (_player.IsAlive() && _fighter.enabled && ShouldAttack())
            {
                if (Vector3.Distance(transform.position, _player.transform.position) - _weaponsRange >= Mathf.Epsilon)
                {
                    _fighter.Attack(_player.gameObject);
                    _mover.SetSpeed(_chaseSpeed);
                }

                _timeSinceLastSawPlayer = 0;
            }
            else if (_timeSinceLastSawPlayer - _suspicionTime <= Mathf.Epsilon)
            {
                _mover.Cancel();
            }
            else
            {
                PatrolBehaviour();
            }
        }
Exemplo n.º 16
0
 private void Update()
 {
     timeSinceLastAttack += Time.deltaTime;
     if (currentTarget == null || currentTarget.IsDead)
     {
         return;
     }
     if (Vector3.Distance(transform.position, currentTarget.transform.position) > equippedWeaponConfig.Range)
     {
         mover.MoveTo(currentTarget.transform.position, 1);
     }
     else
     {
         mover.Cancel();
         AttackBehaviour();
     }
 }
Exemplo n.º 17
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (target && !target.IsDead())
            {
                if (!GetIsRange())
                {
                    Vector3 destination = GetDistanceFromTarget();
                    mover.MoveTo(destination);
                }
                else
                {
                    mover.Cancel();
                    AttackBehaviour();
                }
            }
        }
Exemplo n.º 18
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;

            if (!target || target.IsDead)
            {
                return;
            }

            if (Vector3.Distance(transform.position, target.transform.position) <= weaponRange)
            {
                AttackBehaviour();
                mover.Cancel();
            }
            else
            {
                mover.MoveTo(target.transform.position);
            }
        }
Exemplo n.º 19
0
    // Update is called once per frame
    void Update()
    {
        timeSinceLastAttack += Time.deltaTime;

        if (target == null)
        {
            return;
        }

        if (GetIsInRange())
        {
            mover.SetDestination(target.transform.position, 1f);
        }
        else
        {
            mover.Cancel();
            AttackBehaviour();
        }
    }
Exemplo n.º 20
0
        private void MoveToEnemyToAttack()
        {
            if (target == null)
            {
                return;
            }
            if (target.IsDead())
            {
                return;
            }

            if (!GetIsInRange(target.transform))
            {
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 21
0
        private void MoveToTheTarget()
        {
            if (target == null)
            {
                return;
            }
            if (target.IsDead())
            {
                return;
            }

            if (target != null && !IsInRange(target.transform))
            {
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 22
0
 private void ProcessAttack()
 {
     if (GetIsInRange(target.transform))
     {
         mover.Cancel();
         AttackBehaviour();
     }
     else
     {
         mover.MoveTo(target.transform.position, 1f);
     }
 }
Exemplo n.º 23
0
        private void MoveToAttack()
        {
            if (_target == null)
            {
                return;
            }

            if (!GetIsInRange())
            {
                _mover.MoveTo(_target.transform.position, 1f);
            }
            else
            {
                _mover.Cancel();

                if (_timeSinceLastAttack > _timeBetweenAttacks)
                {
                    AttackBehaviour();
                    _timeSinceLastAttack = 0;
                }
            }
        }
Exemplo n.º 24
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;
            if (target != null)
            {
                mover.MoveTo(target.transform.position, agent, 1);
                if (TargetIsInWeaponRange())
                {
                    mover.Cancel();

                    AttackBehaviour();
                }
            }
        }
Exemplo n.º 25
0
 private void Update()
 {
     if (target != null && CanAttack(target.gameObject))
     {
         if (!GetIsInRange())
         {
             mover.MoveTo(target.transform.position, attackSpeedFraction);
         }
         else
         {
             mover.Cancel();
             AttackBehaviour();
         }
     }
 }
Exemplo n.º 26
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;
            bool isInAttack = GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Attack");

            if (target == null || target.IsDead())
            {
                return;
            }

            if (!GetIsInRange(target.transform))
            {
                if (isInAttack)
                {
                    GetComponent <Animator>().SetTrigger("attackCancel");
                }
                mover.MoveTo(target.transform.position, 1f);
            }
            else
            {
                mover.Cancel();
                AttackBehaviour();
            }
        }
Exemplo n.º 27
0
        private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;
            //print(timeSinceLastAttack);

            if (target == null)
            {
                return;
            }
            if (target.GetComponent <Health>().IsDead())
            {
                return;
            }

            if (IsInRange())
            {
                _mover.Cancel();
                AttackBehavior();
            }
            else
            {
                _mover.MoveTo(target.position, 1f);
            }
        }
Exemplo n.º 28
0
        // Update is called once per frame
        void Update()
        {
            anim.SetFloat("attackSpeed", attackSpeed);
            timeSinceAttack += Time.deltaTime;
            // print("timeSinceAttack: " + timeSinceAttack);
            if (numberOfAttack > maxNumberOfAttack || timeSinceAttack > maxTimeGapBetweenAttacks)
            {
                tempMaxNumberOfAttack = 1;
                numberOfAttack        = 0;
                StopAttack();
            }
            if (target == null)
            {
                return;
            }
            if (target.IsDead())
            {
                StopAttack();
                target = null;
                return;
            }

            // if (!GetIsInRange(target.transform)&&!isAttacking)
            // {
            //     mover.MoveTo(target.transform.position, 1f);
            // }
            // else if (target)
            if (GetIsInRange(target.transform) && !isAttacking && target)
            {
                mover.Cancel();
                if (stamina.HasStaminaLeft())
                {
                    AttackBehaviour(20f);
                }
            }
        }
Exemplo n.º 29
0
        void Update()
        {
            if (target == null)
            {
                return;
            }

            if (!CheckIsInRange())
            {
                mover.MoveTo(target.position);
            }
            else
            {
                mover.Cancel();
            }
        }
Exemplo n.º 30
0
        void Update()
        {
            if (!target)
            {
                return;
            }
            bool isInRange = Vector3.Distance(target.position, transform.position) <= weaponRange;

            if (!isInRange)
            {
                mover.MoveTo(target.position);
            }
            else
            {
                mover.Cancel();
            }
        }