6 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
11 private float blendSpeed = 10f;
16 Vector3 averagePosition = transform.position;
17 Quaternion averageRotation = transform.rotation;
18 int numGrabbers = activeGrabbers.Count;
19 float weightPerGrabber = 1f / numGrabbers;
21 for (var i = 0; i < activeGrabbers.Count; i++)
23 var activeGrabber = (
Grabber)activeGrabbers[i];
24 averagePosition = Vector3.Lerp(averagePosition, activeGrabber.GrabHandle.position, weightPerGrabber);
25 averageRotation = Quaternion.Lerp(averageRotation, activeGrabber.GrabHandle.rotation, weightPerGrabber);
28 transform.position = Vector3.Lerp(transform.position, averagePosition, Time.deltaTime * blendSpeed);
29 transform.rotation = Quaternion.Lerp(transform.rotation, averageRotation, Time.deltaTime * blendSpeed);
36 GetComponent<Rigidbody>().isKinematic =
true;
37 if (!activeGrabbers.Contains(grabber))
39 activeGrabbers.Add(grabber);
45 Debug.Log(
"Detaching form grabber");
51 if (GrabState ==
GrabStateEnum.Inactive && activeGrabbers.Count == 0)
53 GetComponent<Rigidbody>().isKinematic =
false;
54 GetComponent<Rigidbody>().useGravity =
true;