Exemplo n.º 1
0
    void ApplyPaddleForce(CalculateSubmersion paddleSubmersion, Transform forcePoint, SteamVR_Controller.Device steamVRdevice)
    {
        //try to avoid any unnecessary calculations
        float paddleVelocity = paddleSubmersion.Velocity;

        if (paddleVelocity > deadZone)
        {
            float paddleSubmergArea = paddleSubmersion.GetSubmergArea();
            if (paddleSubmergArea > 0)
            {
                Vector3 paddleDirection = paddleSubmersion.Direction;
                Vector3 currThrust      = -paddleDirection * paddleSubmergArea * paddleThrust;
                float   angleOfImpact   = Vector3.Angle(paddleSubmersion.transform.up, paddleDirection);

                // normalize between the sides of the paddle
                if (angleOfImpact > 90)
                {
                    angleOfImpact = 180 - angleOfImpact;
                }
                // normalized. the greater the angle of impact (obliqueness), the less the intensity
                float intensityOfImpact = 1f - (angleOfImpact * 0.0111111111111111f);
                currThrust *= (intensityOfImpact);

                Vector3 normalizedThrust = currThrust.normalized;
                if (restrictVelocity && paddleVelocity > optimalPaddleVelocity)
                {
                    currThrust = normalizedThrust * governedVelocity;
                }

                steamVRdevice.TriggerHapticPulse((ushort)(currThrust.magnitude * hapticMagnitude));

                rbody.AddForceAtPosition(currThrust * 2, forcePoint.position);

                // *Debugging*
                //print("Paddle thrust: " + currThrust);
                //print("Intensity of impact: " + intensityOfImpact);
                //print("Paddle angle: " + angleOfImpact);
                //print("Paddle direction: " + paddleRSubmersion.Direction);
                //print("Paddle velocity: " + paddleRSubmersion.Velocity);

                //Debug.DrawLine(paddleRSubmersion.transform.position, paddleRSubmersion.transform.right, Color.yellow);
                //Debug.DrawLine(paddleRSubmersion.transform.position, -paddleRSubmersion.Direction, Color.green);

                //
                //forceLine.SetPositions(new Vector3[] { paddleRSubmersion.transform.position + paddleRSubmersion.transform.up,
                //                                       paddleRSubmersion.transform.position,
                //                                        paddleRSubmersion.transform.position + paddleRSubmersion.Direction * 10 });
                //forceLine.SetVertexCount(2);
                //forceLine.SetPositions(new Vector3[] { forcePointR.transform.position, currThrust });

                //if (currThrust.magnitude <= 0)
                //{
                //    forceLine.SetPositions(new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, 0, 0) });
                //}
                //else {

                //}
            }
        }
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        deviceR           = SteamVR_Controller.Input(2);
        deviceL           = SteamVR_Controller.Input(1);
        rbody             = GetComponent <Rigidbody>();
        paddleRSubmersion = paddleR.GetComponent <CalculateSubmersion>();
        paddleLSubmersion = paddleL.GetComponent <CalculateSubmersion>();

        forceLine    = GetComponent <LineRenderer>();
        audioUtility = GameObject.FindObjectOfType(typeof(AudioUtility)) as AudioUtility;
        lastRotation = transform.rotation.y;
    }