Exemple #1
0
    void checkGrab(HandScript hand, RaycastHit hit)
    {
        if (hit.distance < hand.armLength)
        {
            aSource.PlayOneShot(grabClip);

            grabbing = true;
            hand.grabHold(hit);

            Vector3 upVector = VectorFunctions.parallelVectorToNormal(transform.up, hit.normal);
            if (upVector == Vector3.zero)
            {
                upVector = -hand.side * Vector3.Cross(transform.forward, hit.normal);
                print("altered");
            }
            Vector3 forwardVector = hand.side * Vector3.Cross(upVector, hit.normal);

            //print("normal: " + hit.normal);
            //print("upVector: " + upVector);

            // print(upVector.normalized);

            targetRotation = Quaternion.LookRotation(forwardVector, upVector);

            //targetPosition = hit.point + 0.7f * hit.normal - 1f*forwardVector.normalized;
            targetPosition = hit.point - hand.restingPoint.x * hit.normal - hand.restingPoint.y * upVector.normalized - hand.restingPoint.z * forwardVector.normalized;

            //print(VectorFunctions.findVectorInDirection(new Vector3(-1, 0, 0), new Vector3(1, 0, 0)));
        }
        else
        {
            grabbing = false;
            hand.releaseHold();
        }
    }