Exemplo n.º 1
0
    private void Move()
    {
        if (_movementBlocked)
        {
            return;
        }

        var dt        = Time.deltaTime;
        var movingDir = new Vector2(_moveLeftRightValue, _moveUpDownValue);

        if (_pointManager.IsServing(playerId) && !serveDone)
        {
            var posZ = transform.position.z;
            var spd  = _tv.WalkSpeed * movingDir.magnitude;
            var dz   = dt * spd * _moveLeftRightValue;
            if (_pointManager.ServicePositionOutOfBounds(playerId, posZ + dz + 1 * Mathf.Sign(_moveLeftRightValue)))
            {
                _reachedServingBound = true;
                dz = posZ;
            }
            else
            {
                _reachedServingBound = false;
            }

            _characterController.SimpleMove(Vector3.zero);
            if (!_reachedServingBound)
            {
                var move = new Vector3(0, 0, dz);
                _characterController.Move(move);
            }

            _animator.SetFloat(_strafeHash, _reachedServingBound ? 0 : _moveLeftRightValue * 0.5f);
            _animator.SetFloat(_forwardHash, 0);
        }
        else
        {
            var manhattanNorm = Math.Abs(movingDir[0]) + Math.Abs(movingDir[1]);
            if (manhattanNorm == 0)
            {
                manhattanNorm = 1;
            }

            var spd = (_actionMapper.IsSprinting() ? _tv.SprintSpeed : _tv.RunSpeed) * movingDir.magnitude;
            var dx  = transform.position.x < 0 ? dt * (_moveUpDownValue < 0 ? _tv.BackSpeed : spd) * _moveUpDownValue / manhattanNorm : 0;
            var dz  = dt * spd * _moveLeftRightValue / manhattanNorm;

            _characterController.SimpleMove(Vector3.zero);
            var move = new Vector3(dx, 0, dz);

            _animator.SetFloat(_strafeHash, _moveLeftRightValue);
            _animator.SetFloat(_forwardHash, _moveUpDownValue);
            _characterController.Move(move);
        }
    }