AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GrabbableSpringJoint.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 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
7 {
13  {
14  //expose the joint variables here for editing because the joint is added/destroyed at runtime
15  // to understand how these variables work in greater depth see unity documentation for spring joint and fixed joint
16  [SerializeField]
17  protected float spring;
18  [SerializeField]
19  protected float damper;
20  [SerializeField]
21  protected float breakForce;
22  [SerializeField]
23  protected float breakTorque;
24  [SerializeField]
25  protected float tolerance;
26  [SerializeField]
27  protected Vector3 joint_anchor;
28  [SerializeField]
29  protected float minDistance;
30  [SerializeField]
31  protected float maxDistance;
32 
33  protected override void AttachToGrabber(BaseGrabber grabber)
34  {
35  base.AttachToGrabber(grabber);
36  SpringJoint joint = gameObject.GetComponent<SpringJoint>();
37  if (joint == null)
38  {
39  joint = gameObject.AddComponent<SpringJoint>();
40  }
41  joint.connectedBody = grabber.GetComponent<Rigidbody>();
42  joint.anchor = new Vector3(0, 0.01f, 0.01f);
43  joint.tolerance = tolerance;
44  joint.breakForce = breakForce;
45  joint.breakTorque = breakTorque;
46  joint.spring = spring;
47  joint.damper = damper;
48  }
49 
50  protected override void DetachFromGrabber(BaseGrabber grabber)
51  {
52  base.DetachFromGrabber(grabber);
53  SpringJoint joint = gameObject.GetComponent<SpringJoint>();
54  if (joint != null)
55  {
56  joint.connectedBody = null;
57  //Destroy(joint);
58  StartCoroutine(DestroyJointAfterDelay(joint));
59  }
60  }
61 
62  protected IEnumerator DestroyJointAfterDelay (SpringJoint joint)
63  {
64  yield return null;
65  if (GrabState == GrabStateEnum.Inactive)
66  {
67  Destroy(joint);
68  }
69  }
70  }
71 }
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...
This type of grab creates a temporary spring joint to attach the grabbed object to the grabber The fi...