AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GrabbableFixedJoint.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System.Collections;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
8 {
14  {
15  // expose the joint variables here for editing because the joint is added/destroyed at runtime
16  // to understand how these variables work in greater depth see documentation for spring joint and fixed joint
17  [SerializeField]
18  protected float breakForce = 20;
19 
20  [SerializeField]
21  protected float breakTorque = 20;
22 
23  [SerializeField]
24  protected float tolerance = 0.01f;
25 
26  [SerializeField]
27  protected Vector3 jointAnchor;
28 
29  [SerializeField]
30  protected float minDistance;
31 
32  [SerializeField]
33  protected float maxDistance;
34 
35  protected override void AttachToGrabber(BaseGrabber grabber)
36  {
37  base.AttachToGrabber(grabber);
38  FixedJoint joint = GetComponent<FixedJoint>();
39  if (joint == null)
40  {
41  joint = gameObject.AddComponent<FixedJoint>();
42  }
43  joint.connectedBody = grabber.GetComponent<Rigidbody>();
44  joint.anchor = jointAnchor;
45  joint.breakForce = breakForce;
46  joint.breakTorque = breakTorque;
47  }
48 
49  protected override void DetachFromGrabber(BaseGrabber grabber)
50  {
51  base.DetachFromGrabber(grabber);
52  FixedJoint joint = GetComponent<FixedJoint>();
53  if (joint != null)
54  {
55  joint.connectedBody = null;
56  //DestroyImmediate(joint);
57  StartCoroutine(DestroyJointAfterDelay(joint));
58  }
59  }
60 
61  protected IEnumerator DestroyJointAfterDelay(FixedJoint joint)
62  {
63  yield return null;
64  if (GrabState == GrabStateEnum.Inactive)
65  {
66  DestroyImmediate(joint);
67  }
68  yield return null;
69  }
70  }
71 }
This type of grab creates a temporary fixed joint to attach the grabbed object to the grabber The fix...
Intended usage: scripts that inherit from this can be attached to the controller, or any object with ...
Definition: BaseGrabber.cs:18
//Intended Usage// Attach a "grabbable_x" script (a script that inherits from this) to any object tha...