Ejemplo n.º 1
0
        private void Update()
        {
            if (!_enemy.IsDead())
            {
                if (_rotateToPlayer)
                {
                    transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_player.transform.position - transform.position, transform.up), Time.deltaTime * rotationSpeed);
                }

                if (_sensor.Hitted(out _lastTagHitted))
                {
                    if (_lastTagHitted == "Player")
                    {
                        CanAttack(true);
                        _nextRangeAttack = Time.timeSinceLevelLoad + rangeCooldown;
                    }
                }

                if (_sensor.Exited(out _lastTagHitted))
                {
                    if (_lastTagHitted == "Player")
                    {
                        CanAttack(false);
                    }
                }


                if (_isClose)
                {
                    _agent.isStopped = true;
                    _agent.SetDestination(transform.position);
                    _canFollow = false;

                    if (Vector3.Dot(transform.forward, _player.transform.position - transform.position) > 0.9f)
                    {
                        if (!_isAttacking)
                        {
                            HitPlayer();
                        }
                    }
                    else
                    {
                        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_player.transform.position - transform.position, transform.up), Time.deltaTime * rotationSpeed);
                    }
                }

                if (!_isOnMelee && !_isRangeAttacking && Vector3.Distance(_player.transform.position, transform.position) < 6f)
                {
                    transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_player.transform.position - transform.position, transform.up), 2f);
                }
            }
        }
Ejemplo n.º 2
0
        private void Update()
        {
            if (_spotted)
            {
                //transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_player.transform.position - transform.position, transform.up), Time.deltaTime * rotationSpeed);
            }

            if (!_enemy.IsDead())
            {
                if (_sensor.Hitted(out _lastTagHitted))
                {
                    if (_lastTagHitted == "Player")
                    {
                        CanAttack(true);
                    }
                }

                if (_sensor.Exited(out _lastTagHitted))
                {
                    if (_lastTagHitted == "Player")
                    {
                        CanAttack(false);
                    }
                }


                if (_isClose)
                {
                    _agent.isStopped = true;
                    _agent.SetDestination(transform.position);
                    _canFollow = false;

                    if (Vector3.Dot(transform.forward, _player.transform.position - transform.position) > 1f)
                    {
                        if (!_isAttacking)
                        {
                            HitPlayer();
                        }
                    }
                    else
                    {
                        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_player.transform.position - transform.position, transform.up), Time.deltaTime * rotationSpeed);
                    }
                }
            }
        }