Skip to content

Commit 9624e4e

Browse files
committed
fix(SnapDropZone): prevent unwanted unsnap on leaving trigger collider
The Snap Drop Zone will automatically unsnap an object if it leaves the trigger collider of the snap drop zone. However, this isn't always the correct result. If the snap drop zone is using a joint snap and the joint is set to infinity, then it would never be expected to break the joint. Also, if the interactable object can only be dropped in snap drop zones then forcing it out of the snap drop zone when it leaves the trigger collider is also incorrect.
1 parent 71bd8c1 commit 9624e4e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Assets/VRTK/Prefabs/Internal/Scripts/VRTK_SnapDropZone.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ protected virtual void CheckCanSnap(VRTK_InteractableObject interactableObjectCh
419419

420420
protected virtual void CheckCanUnsnap(VRTK_InteractableObject interactableObjectCheck)
421421
{
422-
if (interactableObjectCheck != null && currentValidSnapInteractableObjects.Contains(interactableObjectCheck))
422+
if (interactableObjectCheck != null && currentValidSnapInteractableObjects.Contains(interactableObjectCheck) && ValidUnsnap(interactableObjectCheck))
423423
{
424424
if (isSnapped && currentSnappedObject == interactableObjectCheck)
425425
{
@@ -444,6 +444,11 @@ protected virtual void CheckCanUnsnap(VRTK_InteractableObject interactableObject
444444
}
445445
}
446446

447+
protected virtual bool ValidUnsnap(VRTK_InteractableObject interactableObjectCheck)
448+
{
449+
return ((snapType != SnapTypes.UseJoint || !float.IsInfinity(GetComponent<Joint>().breakForce)) && interactableObjectCheck.validDrop == VRTK_InteractableObject.ValidDropTypes.DropAnywhere);
450+
}
451+
447452
protected virtual void SnapObjectToZone(VRTK_InteractableObject objectToSnap)
448453
{
449454
if (!isSnapped && ValidSnapObject(objectToSnap, false))

0 commit comments

Comments
 (0)