Пример #1
0
    public void MoveCharacter(MovingDirections direction)
    {
        if (_canMove)
        {
            _isTurningToLook = false;
            switch (direction)
            {
            case MovingDirections.None:
                _rigidBody.velocity = Vector3.zero;
                if (_animator != null)
                {
                    _animator.SetMovement(false);
                }
                break;

            default:
                Vector3 finalDirection = GetPositionRelativeToCamera(direction);
                _targetDir = gameObject.transform.position + finalDirection;
                _animator.SetMovement(true);

                if (!_isCharging)
                {
                    _rigidBody.velocity = (finalDirection * Speed);
                    _animator.SetCharge(false);
                    _animator.SetSpeed(Speed);
                }
                else
                {
                    _rigidBody.velocity = (finalDirection * ChargeSpeed);
                    _animator.SetCharge(true);
                }
                break;
            }
        }
    }
Пример #2
0
    void Update()
    {
        Transform playerPosition = GameMaster.Instance.GetPlayer().transform;

        RotateTowards(playerPosition);

        //If Can move, move to the player's position
        if (_canMove)
        {
            _agent.isStopped = false;

            if (_agent.remainingDistance > _agent.stoppingDistance)
            {
                _animator.SetMovement(true);
                _animator.SetSpeed(_agent.speed);
            }
            else
            {
                _animator.SetMovement(false);
            }

            _agent.destination = playerPosition.position;
            // If not, stop
        }
        else
        {
            _animator.SetMovement(false);
            _agent.isStopped = true;
        }

        //If is in rage, always look at him and Attack him
        if (IsInMeleeRangeOf(playerPosition))
        {
            _enemyManager.AttackStart(Vector3.zero);
        }
    }