コード例 #1
0
    private void Update()
    {
        if (_inputState.IsPressed(Buttons.THROW) && _holdingState.HoldingBall)
        {
            var ball = _holdingState.StopHoldingBall();

            var ballBody = ball.GetComponent <Rigidbody>();

            var forceAxis = _holdingState.HoldingIn.forward; //the forward axis relative to the object's current rotation

            var force = forceAxis * ThrowPower;

            ballBody.AddForce(force, ForceMode.VelocityChange); //we don't want to have to worry about the weight of the ball... at least not yet
        }
    }
コード例 #2
0
ファイル: ThrowBall.cs プロジェクト: DarkXieon/Leriche
    private void Update()
    {
        if (isLocalPlayer)
        {
            if (_inputState.IsPressed(Buttons.THROW) && _holdingState.HoldingBall) //if the throw button is pressed and the player is holding the ball...
            {
                if (_currentHoldTime == 0f)
                {
                    CmdStartAimAnimation();

                    _audioController.PlayAudio(AudioClips.PlayerThrowV1);
                }

                _currentHoldTime = _inputState.GetButtonHoldTime(Buttons.THROW);

                CmdSetPowerOverlay(Mathf.Min(_currentHoldTime / _maxPowerHoldTime, 1.00f));
            }
            else if (!_inputState.IsPressed(Buttons.THROW) && _holdingState.HoldingBall && _currentHoldTime > 0f) //if the throw button is not pressed, the player is holding the ball, and the player WAS holding the throw button
            {
                var ball = _holdingState.StopHoldingBall();

                //CmdThrowBallAction();

                //this.WaitForCondition(obj => ball.GetComponent<NetworkIdentity>().hasAuthority, () =>
                //{
                //    var ballBody = ball.GetComponent<Rigidbody>();
                //    var ballState = ball.GetComponent<BallThrownState>();

                //    var forceAxis = transform.GetComponentInChildren<Camera>().transform.forward;
                //    var holdTimeMultiplier = Mathf.Min(_currentHoldTime / _maxPowerHoldTime, 1.00f); //this changes power based on hold time
                //    var force = holdTimeMultiplier * (_maxThrowPower - _minThrowPower) + _minThrowPower;
                //    var forceOnAxis = forceAxis * force;

                //    ballBody.AddForce(forceOnAxis, ForceMode.VelocityChange); //we don't want to have to worry about the weight of the ball... at least not yet
                //    ballState.BallThrownBy(gameObject);

                //    CmdStartThrowAnimation();
                //    CmdSetPowerOverlay(0f);

                //    _currentHoldTime = 0f;
                //});

                ThrowBallAction(ball);
                CmdSetBallThrown(ball);

                //var ballBody = ball.GetComponent<Rigidbody>();
                //var ballState = ball.GetComponent<BallThrownState>();

                //var forceAxis = transform.GetComponentInChildren<Camera>().transform.forward;
                //var holdTimeMultiplier = Mathf.Min(_currentHoldTime / _maxPowerHoldTime, 1.00f); //this changes power based on hold time
                //var force = holdTimeMultiplier * (_maxThrowPower - _minThrowPower) + _minThrowPower;
                //var forceOnAxis = forceAxis * force;

                //ballBody.AddForce(forceOnAxis, ForceMode.VelocityChange); //we don't want to have to worry about the weight of the ball... at least not yet
                //ballState.BallThrownBy(gameObject);

                CmdStartThrowAnimation();
                CmdSetPowerOverlay(0f);

                _currentHoldTime = 0f;
            }
        }
    }