HoverLock() public method

Continue to hover over this object indefinitely, whether or not the VRHand moves out of its interaction trigger volume.
public HoverLock ( VRInteractable interactable ) : void
interactable VRInteractable The VRInteractable to hover over indefinitely.
return void
	/// <summary>
	/// Called every Update() while a VRHand is hovering over me.
	/// </summary>
	/// <param name="hand"></param>
	void HandHoverUpdate( VRHand hand )
	{
		if ( hand.GetStandardInteractionButtonDown() || ( ( hand.controller != null ) && hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_Grip ) ) )
		{
			if ( hand.currentAttachedObject != gameObject )
			{
				// Save our position/rotation so that we can restore it when we detach
				oldPosition = transform.position;
				oldRotation = transform.rotation;

				// Call this to continue receiving HandHoverUpdate messages,
				// and prevent the hand from hovering over anything else
				hand.HoverLock( GetComponent<VRInteractable>() );

				// Attach this object to the hand
				hand.AttachObject( gameObject, false );
			}
			else
			{
				// Detach this object from the hand
				hand.DetachObject( gameObject );

				// Call this to undo HoverLock
				hand.HoverUnlock( GetComponent<VRInteractable>() );

				// Restore position/rotation
				transform.position = oldPosition;
				transform.rotation = oldRotation;
			}
		}
	}
Example #2
0
    /// <summary>
    /// Called every Update() while a VRHand is hovering over me.
    /// </summary>
    /// <param name="hand"></param>
    void HandHoverUpdate(VRHand hand)
    {
        if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)))
        {
            if (hand.currentAttachedObject != gameObject)
            {
                // Save our position/rotation so that we can restore it when we detach
                oldPosition = transform.position;
                oldRotation = transform.rotation;

                // Call this to continue receiving HandHoverUpdate messages,
                // and prevent the hand from hovering over anything else
                hand.HoverLock(GetComponent <VRInteractable>());

                // Attach this object to the hand
                hand.AttachObject(gameObject, attachmentFlags);
            }
            else
            {
                // Detach this object from the hand
                hand.DetachObject(gameObject);

                // Call this to undo HoverLock
                hand.HoverUnlock(GetComponent <VRInteractable>());

                // Restore position/rotation
                transform.position = oldPosition;
                transform.rotation = oldRotation;
            }
        }
    }
	void OnAttachedToHand( VRHand hand )
	{
		attached = true;

		hand.HoverLock( null );
		
		Rigidbody rb = GetComponent<Rigidbody>();
		rb.isKinematic = true;
		rb.interpolation = RigidbodyInterpolation.None;

		velocityEstimator.BeginEstimatingVelocity();
	}
Example #4
0
    //-----------------------------------------------------
    public void PhysicsAttach(VRHand hand)
    {
        PhysicsDetach(hand);

        Rigidbody holdingBody  = null;
        Vector3   holdingPoint = Vector3.zero;

        // The hand should grab onto the nearest rigid body
        float closestDistance = float.MaxValue;

        for (int i = 0; i < rigidBodies.Count; i++)
        {
            float distance = Vector3.Distance(rigidBodies[i].worldCenterOfMass, hand.transform.position);
            if (distance < closestDistance)
            {
                holdingBody     = rigidBodies[i];
                closestDistance = distance;
            }
        }

        // Couldn't grab onto a body
        if (holdingBody == null)
        {
            return;
        }

        // Create a fixed joint from the hand to the holding body
        if (attachMode == AttachMode.FixedJoint)
        {
            Rigidbody handRigidbody = FindOrAddComponent <Rigidbody>(hand.gameObject);
            handRigidbody.isKinematic = true;

            FixedJoint handJoint = hand.gameObject.AddComponent <FixedJoint>();
            handJoint.connectedBody = holdingBody;
        }

        // Don't let the hand interact with other things while it's holding us
        hand.HoverLock(null);

        // Affix this point
        Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMass;

        offset       = Mathf.Min(offset.magnitude, 1.0f) * offset.normalized;
        holdingPoint = holdingBody.transform.InverseTransformPoint(holdingBody.worldCenterOfMass + offset);

        hand.AttachObject(this.gameObject, attachmentFlags);

        // Update holding list
        holdingHands.Add(hand);
        holdingBodies.Add(holdingBody);
        holdingPoints.Add(holdingPoint);
    }
    void OnAttachedToHand(VRHand hand)
    {
        attached = true;

        hand.HoverLock(null);

        Rigidbody rb = GetComponent <Rigidbody>();

        rb.isKinematic   = true;
        rb.interpolation = RigidbodyInterpolation.None;

        velocityEstimator.BeginEstimatingVelocity();
    }
    void HandHoverUpdate( VRHand hand )
    {
        if ( hand.currentAttachedObject )
            return;

        if ( hand.GetStandardInteractionButtonDown() )
        {
            hand.HoverLock( GetComponent<VRInteractable>() );
        }

        if ( hand.GetStandardInteractionButtonUp() )
        {
            hand.HoverUnlock( GetComponent<VRInteractable>() );
        }

        if ( hand.GetStandardInteractionButton() )
        {
            UpdateLinearMapping( hand.transform );
        }
    }
Example #7
0
    void HandHoverUpdate(VRHand hand)
    {
        if (hand.currentAttachedObject)
        {
            return;
        }

        if (hand.GetStandardInteractionButtonDown())
        {
            hand.HoverLock(GetComponent <VRInteractable>());
        }

        if (hand.GetStandardInteractionButtonUp())
        {
            hand.HoverUnlock(GetComponent <VRInteractable>());
        }

        if (hand.GetStandardInteractionButton())
        {
            UpdateLinearMapping(hand.transform);
        }
    }
	void HandHoverUpdate( VRHand hand )
	{
		if ( hand.GetStandardInteractionButtonDown() )
		{
			hand.HoverLock( GetComponent<VRInteractable>() );

			initialMappingOffset = linearMapping.value - CalculateLinearMapping( hand.transform );
			sampleCount = 0;
			mappingChangeRate = 0.0f;
		}

		if ( hand.GetStandardInteractionButtonUp() )
		{
			hand.HoverUnlock( GetComponent<VRInteractable>() );

			CalculateMappingChangeRate();
		}

		if ( hand.GetStandardInteractionButton() )
		{
			UpdateLinearMapping( hand.transform );
		}
	}
    void HandHoverUpdate(VRHand hand)
    {
        if (hand.GetStandardInteractionButtonDown())
        {
            hand.HoverLock(GetComponent <VRInteractable>());

            initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform);
            sampleCount          = 0;
            mappingChangeRate    = 0.0f;
        }

        if (hand.GetStandardInteractionButtonUp())
        {
            hand.HoverUnlock(GetComponent <VRInteractable>());

            CalculateMappingChangeRate();
        }

        if (hand.GetStandardInteractionButton())
        {
            UpdateLinearMapping(hand.transform);
        }
    }