Skip to content

Commit 22a1ca7

Browse files
authored
Merge pull request #194 from De-Panther/interactables_velocity
Added velocity for interactables when dropped
2 parents b9225ba + 8f2c5c9 commit 22a1ca7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
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 & 1 deletion
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;
@@ -125,6 +128,9 @@ private void Update()
125128
Drop();
126129
}
127130

131+
currentVelocity = (transform.position - previousPos) / Time.deltaTime;
132+
previousPos = transform.position;
133+
128134
#if WEBXR_INPUT_PROFILES
129135
if (loadedModel && useInputProfile)
130136
{
@@ -512,7 +518,7 @@ public void Drop()
512518
{
513519
if (!currentRigidBody)
514520
return;
515-
521+
currentRigidBody.velocity = currentVelocity;
516522
attachJoint.connectedBody = null;
517523
currentRigidBody = null;
518524
}

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

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

1315
void Awake()
1416
{
@@ -27,6 +29,7 @@ void OnMouseDown()
2729

2830
void OnMouseUp()
2931
{
32+
m_rigidbody.velocity = m_currentVelocity;
3033
m_currentCamera = null;
3134
}
3235

@@ -37,6 +40,8 @@ void FixedUpdate()
3740
Vector3 currentScreenPoint = GetMousePosWithScreenZ(m_screenPoint.z);
3841
m_rigidbody.velocity = Vector3.zero;
3942
m_rigidbody.MovePosition(m_currentCamera.ScreenToWorldPoint(currentScreenPoint) + m_offset);
43+
m_currentVelocity = (transform.position - m_previousPos) / Time.deltaTime;
44+
m_previousPos = transform.position;
4045
}
4146
}
4247

0 commit comments

Comments
 (0)