Skip to content

Commit 8f2c5c9

Browse files
committed
Velocity for interactables when dropped
1 parent 97f55a5 commit 8f2c5c9

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Support for AR headsets in SceneHitTest.
10+
- Velocity for interactables when dropped.
1011

1112
## [0.13.0] - 2021-10-18
1213
### Changed

Packages/webxr-interactions/Runtime/Scripts/ControllerInteraction.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class ControllerInteraction : MonoBehaviour
3333
private Dictionary<int, Transform> handJoints = new Dictionary<int, Transform>();
3434
public GameObject inputProfileHandModelParent;
3535

36+
private Vector3 currentVelocity;
37+
private Vector3 previousPos;
38+
3639
#if WEBXR_INPUT_PROFILES
3740
private InputProfileLoader inputProfileLoader;
3841
private InputProfileModel inputProfileModel;
@@ -45,9 +48,6 @@ public class ControllerInteraction : MonoBehaviour
4548
private string loadedHandProfile = null;
4649
private Dictionary<int, Transform> handModelJoints = new Dictionary<int, Transform>();
4750
private static Quaternion quat180 = Quaternion.Euler(0, 180, 0);
48-
49-
private Vector3 currentVelocity;
50-
private Vector3 previousPos;
5151
#endif
5252

5353
private void Awake()
@@ -128,6 +128,9 @@ private void Update()
128128
Drop();
129129
}
130130

131+
currentVelocity = (transform.position - previousPos) / Time.deltaTime;
132+
previousPos = transform.position;
133+
131134
#if WEBXR_INPUT_PROFILES
132135
if (loadedModel && useInputProfile)
133136
{
@@ -286,9 +289,7 @@ private void OnHandUpdate(WebXRHandData handData)
286289
return;
287290
}
288291
Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);
289-
currentVelocity = (transform.position - previousPos) / Time.deltaTime;
290-
previousPos = transform.position;
291-
292+
292293
#if WEBXR_INPUT_PROFILES
293294
if (useInputProfile && loadedHandModel)
294295
{

Packages/webxr-interactions/Runtime/Scripts/MouseDragObject.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class MouseDragObject : MonoBehaviour
99
private Rigidbody m_rigidbody;
1010
private Vector3 m_screenPoint;
1111
private Vector3 m_offset;
12-
private Vector3 currentVelocity;
13-
private Vector3 previousPos;
12+
private Vector3 m_currentVelocity;
13+
private Vector3 m_previousPos;
1414

1515
void Awake()
1616
{
@@ -29,7 +29,7 @@ void OnMouseDown()
2929

3030
void OnMouseUp()
3131
{
32-
m_rigidbody.velocity = currentVelocity;
32+
m_rigidbody.velocity = m_currentVelocity;
3333
m_currentCamera = null;
3434
}
3535

@@ -40,9 +40,8 @@ void FixedUpdate()
4040
Vector3 currentScreenPoint = GetMousePosWithScreenZ(m_screenPoint.z);
4141
m_rigidbody.velocity = Vector3.zero;
4242
m_rigidbody.MovePosition(m_currentCamera.ScreenToWorldPoint(currentScreenPoint) + m_offset);
43-
44-
currentVelocity = (transform.position - previousPos) / Time.deltaTime;
45-
previousPos = transform.position;
43+
m_currentVelocity = (transform.position - m_previousPos) / Time.deltaTime;
44+
m_previousPos = transform.position;
4645
}
4746
}
4847

0 commit comments

Comments
 (0)