Exemplo n.º 1
0
    private void UpdateConnectionLine()
    {
        /*
         * xVector = hand.transform.position - transform.position;
         *
         * float distance = xVector.magnitude;
         * Vector3 hypVector = transform.forward;
         * float angle = Vector3.Angle(xVector, hypVector);
         * if (angle > 25f)
         * {
         *  hypVector = Vector3.RotateTowards(transform.forward, xVector, (angle * Mathf.Deg2Rad) - (25f * Mathf.Deg2Rad), 0.0f);
         *  hypVector.Normalize();
         *  angle = Vector3.Angle(xVector, hypVector);
         * }
         * float hyp = distance / Mathf.Cos(angle * Mathf.Deg2Rad);
         *
         *
         * yVector = (hypVector * hyp) - xVector;
         *
         * xVector.Normalize();
         * yVector.Normalize();
         *
         * float Vo = Mathf.Sqrt((distance * 9.8f) / Mathf.Sin(2 * angle * Mathf.Deg2Rad));
         * float Vx = Vo * Mathf.Cos(angle * Mathf.Deg2Rad);
         * float Vy = Vo * Mathf.Sin(angle * Mathf.Deg2Rad);
         *
         *
         * float timeTotal = 2 * Vo * Mathf.Sin(angle * Mathf.Deg2Rad) / 9.8f;
         * float interval = timeTotal / segments.Length;
         * for (int i = 0; i < segments.Length; i++)
         * {
         *  float time = interval * i;
         *
         *  Vector3 xPos = xVector * Vx * time;
         *  Vector3 yPos = yVector * (Vy * time - 0.5f * 9.8f * time * time);
         *
         *  segments[i].transform.position = transform.position + xPos + yPos;
         * }
         */
        ////

        /*
         * if (grabAction.GetStateDown(handType))
         * {
         *  hand.transform.position = transform.position;
         *  handlaunchPoint = transform.position;
         *  handForward = (connectedPoint - transform.position).normalized;
         * }
         *
         * if ((connectedPoint - handlaunchPoint).magnitude <= (hand.transform.position - handlaunchPoint).magnitude)
         * {
         *  hand.transform.position = connectedPoint;
         * }
         * else
         * {
         *  hand.transform.position += handForward * Time.deltaTime * 25f;
         * }
         */

        hand.transform.position = Vector3.Lerp(connectFromPoint, connectToPoint, handTime);

        ///// Bezier curve /////

        Vector3 cp1 = transform.position;
        Vector3 cp3 = hand.transform.position;

        xVector = cp3 - cp1;
        Vector3 hypVector = transform.forward;
        float   angle     = Vector3.Angle(xVector, hypVector);

        if (angle >= 45f)
        {
            angle     = 45f;
            hypVector = Vector3.RotateTowards(xVector, transform.forward, Mathf.Deg2Rad * angle, 0);
            hypVector.Normalize();
        }

        float x = xVector.magnitude / 2f;
        float z = x / Mathf.Cos(Mathf.Deg2Rad * angle);

        Vector3 cp2 = cp1 + (z * hypVector);

        float interval = 1f / segments.Length;
        float t        = 0;

        Vector3 b12, b23;

        for (int i = 0; i < segments.Length; i++)
        {
            b12 = Vector3.Lerp(cp1, cp2, t);
            b23 = Vector3.Lerp(cp2, cp3, t);

            segments[i].transform.position = Vector3.Lerp(b12, b23, t);
            t += interval;
        }



        //////



        //// Move column based on controller velocity
        grabLight.SetActive(false);
        if (grabbedColumn)

        //if (grabbedColumn && angle > 20f)
        {
            //float maxVelocity = 2;
            //float maxAngVelocity = 7;

            float maxVelocity    = 1;
            float maxAngVelocity = 4;

            if ((grabbedColumn.isUpColumn && (controllerPose.GetVelocity().y > maxVelocity || controllerPose.GetAngularVelocity().x < -maxAngVelocity)) ||
                (!grabbedColumn.isUpColumn && (controllerPose.GetVelocity().y < -maxVelocity || controllerPose.GetAngularVelocity().x > maxAngVelocity)))
            {
                grabbedColumn.Pulverize();
                grabbedColumn.movedBySource = transform;
                RetractHand(false);
                Pulse(0.1f, 50, 75);
            }

            if ((hand.transform.position - connectToPoint).magnitude < 0.01 && !grabLight.activeSelf)
            {
                grabLight.SetActive(true);
            }
        }
    }