示例#1
0
文件: AIPlayer.cs 项目: lipusal/VJI
    // Update is called once per frame
    void Update()
    {
        if (_isServing)
        {
            if (!_playerAnimation.isCelebratingOrAngry())
            {
                if (Math.Abs(_timeToServe) < 0.01)
                {
                    _timeToServe = Random.Range(0.0f, 1.0f) + 1.0f;
                }

                _elapsedTime = _elapsedTime + Time.deltaTime;
                if (_elapsedTime >= _timeToServe)
                {
                    AimServe();
                    _elapsedTime = 0;
                    _timeToServe = 0;
                    SetServing(false);
                }
            }
        }
        else
        {
            BallLogic ballLogic = BallLogic.Instance;
            bool      hasMoved  = false;
            if (ballLogic.IsEnabled() && ballLogic.GetHittingPlayer() != _id &&
                ballLogic.GetHittingPlayer() != 0)
            {
                hasMoved = MoveToBall();
            }

            if (!hasMoved)
            {
                _playerAnimation.StartMoveAnimation(MovementDirection.IDLE);
            }
        }
    }
示例#2
0
    private void ReadInput()
    {
        moveLeftRightValue       = 0;
        moveForwardBackwardValue = 0;
        _finishHitting           = false;
        BallLogic ball = BallLogic.Instance;


        if (ActionMapper.GetMoveLeft(leftButton, horizontalAxis))
        {
            moveLeftRightValue += -1;
        }

        if (ActionMapper.GetMoveRight(rightButton, horizontalAxis))
        {
            moveLeftRightValue += 1;
        }

        if (ActionMapper.GetMoveForward(forwardButton, verticalAxis))
        {
            moveForwardBackwardValue += 1;
        }

        if (ActionMapper.GetMoveBackward(backwardButton, verticalAxis))
        {
            moveForwardBackwardValue += -1;
        }

        if (ActionMapper.GetHitPressed(hitButton, hitJoystickButton) && ball.GetHittingPlayer() != _id)
        {
            if (!_isCharging && _isServing)
            {
                _currentHitForce = minHitForce;
                _isCharging      = true;
            }
            else if (!_isCharging && ball.GetHittingPlayer() != 0)
            {
                _currentHitForce = minHitForce;
                if (!_isServing)
                {
                    aimTarget.position = _aimStartPosition;
                    _ballSide          = BallLogic.Instance.GetSide(transform.position);
                    _playerAnimation.StartHittingAnimation(_ballSide);
                }
                _isCharging = true;
            }
            else if (_isCharging)
            {
                _currentHitForce += deltaHitForce * Time.deltaTime;
                _currentHitForce  = Math.Min(_currentHitForce, maxHitForce);
            }
        }

        if (ActionMapper.GetHitReleased(hitButton, hitJoystickButton))
        {
            if (_isServing && ball.GetHittingPlayer() == 0)
            {
                _isCharging = false;
                _playerAnimation.StartServeAnimation();

                _animatedServingBall = Instantiate(animatableServeBallPrefab, transform.position + Vector3.up * animatableServeBallPrefab.GetComponent <BallServeAnimation>().verticalAppearOffset, Quaternion.identity);
            }
        }
    }