Tanoda
HandDrop.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections;
11
12namespace Leap.Unity {
15 private Vector3 startingPalmPosition;
16 private Quaternion startingOrientation;
17 private Transform palm;
18
19 // Use this for initialization
20 protected override void Awake() {
21 base.Awake();
22 palm = GetComponent<HandModel>().palm;
23 startingPalmPosition = palm.localPosition;
24 startingOrientation = palm.localRotation;
25 }
26
27 protected override void HandFinish() {
28 StartCoroutine(LerpToStart());
29 }
30 protected override void HandReset() {
31 StopAllCoroutines();
32 }
33
34 private IEnumerator LerpToStart() {
35 Vector3 droppedPosition = palm.localPosition;
36 Quaternion droppedOrientation = palm.localRotation;
37 float duration = .25f;
38 float startTime = Time.time;
39 float endTime = startTime + duration;
40
41 while (Time.time <= endTime) {
42 float t = (Time.time - startTime) / duration;
43 palm.localPosition = Vector3.Lerp(droppedPosition, startingPalmPosition, t);
44 palm.localRotation = Quaternion.Lerp(droppedOrientation, startingOrientation, t);
45 yield return null;
46 }
47 }
48 }
49}
override void HandReset()
Definition: HandDrop.cs:30
override void Awake()
Definition: HandDrop.cs:20
override void HandFinish()
Definition: HandDrop.cs:27
A component to be attached to a HandModelBase to handle starting and ending of tracking....