Beispiel #1
0
 void OnCollisionExit(Collision c)
 {
     if (isvalid(c.collider))
     {
         touching = null;
     }
 }
    void GrabStart(KnucklesInteractable r, int finger0, int finger1)
    {
        //save which two fingers are holding onto the thing
        gfingers [0]      = finger0;
        gfingers [1]      = finger1;
        gfingerscurls [0] = hc.getposfromindex(gfingers [0]);
        gfingerscurls [1] = hc.getposfromindex(gfingers [1]);

        grabTarget = r;


        grabbing = true;

        grabTarget.rb.useGravity = false;
        //grabTarget.rb.centerOfMass = grabTarget.rb.transform.InverseTransformPoint (phystips [gfingers [0]].transform.position);

        grabPos.position = grabTarget.transform.position;
        grabPos.rotation = grabTarget.transform.rotation;

        if (grabTarget.isSnapping)           // snapPos marks the position of the hand relative to the grabbable object
        {
            snapPos.position = transform.position;
            snapPos.rotation = transform.rotation;
            snapPos.parent   = grabTarget.transform;
        }

        r.Grab();          //tell the Interactable it's been grabbed by this script
    }
Beispiel #3
0
 void OnCollisionStay(Collision c)
 {
     if (isvalid(c.collider))
     {
         colnrm = c.contacts [0].normal;
         if (c.collider.attachedRigidbody.GetComponent <KnucklesInteractable> ().isGrabbable)              // make sure we're actually allowed to pick this up
         {
             touchtemp = c.collider.attachedRigidbody.GetComponent <KnucklesInteractable> ();              // say what we're touching currently
         }
     }
 }
    void GrabEnd(bool drop)      // if drop is false, a different hand has taken control of the thing and we don't need to worry about detaching it
    {
        grabbing = false;

        if (drop)
        {
            //release the thing
            grabTarget.Drop();            //tell it it got dropped
            grabTarget.rb.useGravity = grabTarget.useGravity;
            if (!grabTarget.isSnapping)
            {
                grabTarget.rb.velocity = GetVelocity();
            }
            grabTarget.rb.angularVelocity = GetAngularVelocity();
        }
        //reset the fingers that are holding the thing, just for neatness' sake
        gfingers = new int[2] {
            0, 0
        };
        grabTarget = null;
    }
Beispiel #5
0
    void Update()
    {
        //update the public touching variable and reset touchtemp so it has to be set again by OnCollisionStay during the next frame
        touching = touchtemp;
        if (touchtemp != null)
        {
            touchtemp = null;
        }

        //this mess just resets the finger clamping after 0.2 seconds of not touching anything
        if (touching)
        {
            timer = 0;
        }
        else
        {
            timer += Time.deltaTime;
            if (index < 5 && timer > 0.2f)
            {
                hpi.hc.SetClamp(index, 0);
            }
        }
    }