Skip to content

Commit 2a1d623

Browse files
authored
Merge pull request #189 from smallrice45/patch-2
Update MouseDragObject.cs
2 parents b9225ba + 1c9236d commit 2a1d623

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 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 currentVelocity;
13+
private Vector3 previousPos;
1214

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

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

@@ -37,6 +40,9 @@ 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+
44+
currentVelocity = (transform.position - previousPos) / Time.deltaTime;
45+
previousPos = transform.position;
4046
}
4147
}
4248

0 commit comments

Comments
 (0)