public AttachObject ( GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags, string attachmentPoint = "" ) : void | ||
objectToAttach | GameObject | The GameObject to attach. |
flags | AttachmentFlags | The flags to use for attaching the object. |
attachmentPoint | string | Name of the GameObject in the hierarchy of this VRHand which should act as the attachment point for this GameObject. |
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, 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; } } }
/// <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; } } }
void OnHandHoverBegin( VRHand hand ) { bool showHint = true; // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if ( !attached ) { if ( hand.GetStandardInteractionButton() ) { Rigidbody rb = GetComponent<Rigidbody>(); if ( rb.velocity.magnitude >= catchSpeedThreshold ) { hand.AttachObject( gameObject, attachmentFlags, attachmentPoint ); showHint = false; } } } if ( showHint ) { VRControllerButtonHints.Show( hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger ); } }
void OnHandHoverBegin(VRHand hand) { bool showHint = true; // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if (!attached) { if (hand.GetStandardInteractionButton()) { Rigidbody rb = GetComponent <Rigidbody>(); if (rb.velocity.magnitude >= catchSpeedThreshold) { hand.AttachObject(gameObject, attachmentFlags, attachmentPoint); showHint = false; } } } if (showHint) { VRControllerButtonHints.Show(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); } }
void HandHoverUpdate( VRHand hand ) { //Trigger got pressed if ( hand.GetStandardInteractionButtonDown() ) { hand.AttachObject( gameObject, snapOnAttach, attachmentPoint, detachOthers ); } }
void HandHoverUpdate(VRHand hand) { //Trigger got pressed if (hand.GetStandardInteractionButtonDown()) { hand.AttachObject(gameObject, snapOnAttach, attachmentPoint, detachOthers); } }
void HandHoverUpdate( VRHand hand ) { //Trigger got pressed if ( hand.GetStandardInteractionButtonDown() ) { hand.AttachObject( gameObject, attachmentFlags, attachmentPoint ); VRControllerButtonHints.Hide( hand ); } }
void HandHoverUpdate(VRHand hand) { //Trigger got pressed if (hand.GetStandardInteractionButtonDown()) { hand.AttachObject(gameObject, attachmentFlags, attachmentPoint); VRControllerButtonHints.Hide(hand); } }
//----------------------------------------------------- private void SpawnAndAttachObject( VRHand hand ) { if ( !alreadySpawned ) { GameObject objectToAttach = GameObject.Instantiate( objectToSpawn ); hand.AttachObject( objectToAttach, snapOnAttach, attachmentPoint, detachOthers ); alreadySpawned = true; } }
//----------------------------------------------------- private void SpawnAndAttachObject(VRHand hand) { if (!alreadySpawned) { GameObject objectToAttach = GameObject.Instantiate(objectToSpawn); hand.AttachObject(objectToAttach, snapOnAttach, attachmentPoint, detachOthers); alreadySpawned = true; } }
//----------------------------------------------------- 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 OnHandHoverBegin( VRHand hand ) { // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if ( !attached ) { if ( hand.GetStandardInteractionButton() ) { Rigidbody rb = GetComponent<Rigidbody>(); if ( rb.velocity.magnitude >= catchSpeedThreshold ) { hand.AttachObject( gameObject, snapOnAttach, attachmentPoint, detachOthers ); } } } }
void OnHandHoverBegin(VRHand hand) { // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if (!attached) { if (hand.GetStandardInteractionButton()) { Rigidbody rb = GetComponent <Rigidbody>(); if (rb.velocity.magnitude >= catchSpeedThreshold) { hand.AttachObject(gameObject, snapOnAttach, attachmentPoint, detachOthers); } } } }