Skip to content

Commit dc68df3

Browse files
committed
feat(Interaction): add tracked controller colliders
The Controller Tracked Collider script provides a way of having decoupled controller colliders from the actual controller GameObject. This means that the tracked collider collection is not a child of the controller GameObject so it does not have absolute 1:1 tracking. This is useful as it means the colliders do not follow the controller to every specific position and because it uses Rigidbody mechanics to move the collider collection, the colliders interact within the Unity physics system. This results in being able to pass a controller through another Rigidbody but the colliders for the controller won't pass through with the controller, instead they will be restricted by the Unity physics system. The Controller Rigidbody Activator script has also been updated to allow it to activate these new tracked controller colliders. The Ignore Interact Touch Colliders script has also been updated to ensure these tracked controller colliders are also included in the ignore routine as they are effectively tied to the Interact Touch collider set.
1 parent a911bfe commit dc68df3

File tree

10 files changed

+341
-13
lines changed

10 files changed

+341
-13
lines changed

Assets/VRTK/Documentation/API.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ Provides a simple trigger collider volume that when a controller enters will ena
164164
* Place the `VRTK/Prefabs/ControllerRigidbodyActivator/ControllerRigidbodyActivator` prefab in the scene at the location where the controller rigidbody should be automatically activated.
165165
* The prefab contains a default sphere collider to determine ths collision, this collider component can be customised in the inspector or can be replaced with another collider component (set to `Is Trigger`).
166166

167-
> If the prefab is placed as a child of the target interactable game object then the collider volume on the prefab will trigger collisions on the interactable object.
167+
> If the prefab is placed as a child of the target Interactable Object then the collider volume on the prefab will trigger collisions on the Interactable Object.
168168

169169
### Inspector Parameters
170170

171-
* **Is Enabled:** If this is checked then the collider will have it's rigidbody toggled on and off during a collision.
171+
* **Is Enabled:** If this is checked then the Collider will have it's Rigidbody toggled on and off during a collision.
172+
* **Activate Interact Touch:** If this is checked then the Rigidbody Activator will activate the rigidbody and colliders on the Interact Touch script.
173+
* **Activate Tracked Collider:** If this is checked then the Rigidbody Activator will activate the rigidbody and colliders on the Controller Tracked Collider script.
172174

173175
### Class Events
174176

@@ -3107,6 +3109,7 @@ A collection of scripts that provide the ability denote objects (such as control
31073109
* [Interact Near Touch](#interact-near-touch-vrtk_interactneartouch)
31083110
* [Interact Grab](#interact-grab-vrtk_interactgrab)
31093111
* [Interact Use](#interact-use-vrtk_interactuse)
3112+
* [Controller Tracked Collider](#controller-tracked-collider-vrtk_controllertrackedcollider)
31103113
* [Controller Highlighter](#controller-highlighter-vrtk_controllerhighlighter)
31113114
* [Object Auto Grab](#object-auto-grab-vrtk_objectautograb)
31123115

@@ -3729,7 +3732,7 @@ Determines if the Interact Touch can initiate a grab with the touched Interactab
37293732
* **Grab Button:** The button used to grab/release a touched Interactable Object.
37303733
* **Grab Precognition:** An amount of time between when the grab button is pressed to when the controller is touching an Interactable Object to grab it.
37313734
* **Throw Multiplier:** An amount to multiply the velocity of any Interactable Object being thrown.
3732-
* **Create Rigid Body When Not Touching:** If this is checked and the Interact Touch is not touching an Interactable Object when the grab button is pressed then a rigid body is added to the interacting object to allow it to push other rigid body objects around.
3735+
* **Create Rigid Body When Not Touching:** If this is checked and the Interact Touch is not touching an Interactable Object when the grab button is pressed then a Rigidbody is added to the interacting object to allow it to push other Rigidbody objects around.
37333736
* **Controller Attach Point:** The rigidbody point on the controller model to snap the grabbed Interactable Object to. If blank it will be set to the SDK default.
37343737
* **Controller Events:** The Controller Events to listen for the events on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
37353738
* **Interact Touch:** The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
@@ -3910,6 +3913,56 @@ The AttemptUse method will attempt to use the currently touched Interactable Obj
39103913

39113914
---
39123915

3916+
## Controller Tracked Collider (VRTK_ControllerTrackedCollider)
3917+
> extends VRTK_SDKControllerReady
3918+
3919+
### Overview
3920+
3921+
Provides a controller collider collection that follows the controller rigidbody via the physics system.
3922+
3923+
**Required Components:**
3924+
* `VRTK_InteractTouch` - An Interact Touch script to determine which controller rigidbody to follow.
3925+
3926+
**Optional Components:**
3927+
* `VRTK_ControllerEvents` - The events component to listen for the button presses on. This must be applied in the same object hierarchy as the Interact Touch script if one is not provided via the `Controller Events` parameter.
3928+
3929+
**Script Usage:**
3930+
* Place the `VRTK_ControllerTrackedCollider` script on any active scene GameObject except the Script Alias objects.
3931+
* Assign the controller to track by applying an Interact Touch to the relevant Script Alias and then providing that reference to the `Interact Touch` parameter on this script.
3932+
3933+
### Inspector Parameters
3934+
3935+
* **Interact Touch:** The Interact Touch script to relate the tracked collider to.
3936+
* **Max Resnap Distance:** The maximum distance the collider object can be from the controller before it automatically snaps back to the same position.
3937+
* **Activation Button:** The button to press to activate the colliders on the tracked collider set. If `Undefined` then it will always be active.
3938+
* **Controller Events:** An optional Controller Events to use for listening to the button events. If this is left blank then it will attempt to be retrieved from the same controller as the `Interact Touch` parameter.
3939+
3940+
### Class Methods
3941+
3942+
#### ToggleColliders/1
3943+
3944+
> `public virtual void ToggleColliders(bool state)`
3945+
3946+
* Parameters
3947+
* `bool state` - If `true` then the tracked colliders will be able to affect other Rigidbodies.
3948+
* Returns
3949+
* _none_
3950+
3951+
The ToggleColliders method toggles the collision state of the tracked colliders.
3952+
3953+
#### TrackedColliders/0
3954+
3955+
> `public virtual Collider[] TrackedColliders()`
3956+
3957+
* Parameters
3958+
* _none_
3959+
* Returns
3960+
* `Collider[]` - A Collider array of the tracked colliders.
3961+
3962+
The TrackedColliders method returns an array of the tracked colliders.
3963+
3964+
---
3965+
39133966
## Controller Highlighter (VRTK_ControllerHighlighter)
39143967

39153968
### Overview

Assets/VRTK/Prefabs/ControllerRigidbodyActivator/VRTK_ControllerRigidbodyActivator.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ public struct ControllerRigidbodyActivatorEventArgs
2727
/// * Place the `VRTK/Prefabs/ControllerRigidbodyActivator/ControllerRigidbodyActivator` prefab in the scene at the location where the controller rigidbody should be automatically activated.
2828
/// * The prefab contains a default sphere collider to determine ths collision, this collider component can be customised in the inspector or can be replaced with another collider component (set to `Is Trigger`).
2929
///
30-
/// > If the prefab is placed as a child of the target interactable game object then the collider volume on the prefab will trigger collisions on the interactable object.
30+
/// > If the prefab is placed as a child of the target Interactable Object then the collider volume on the prefab will trigger collisions on the Interactable Object.
3131
/// </remarks>
3232
public class VRTK_ControllerRigidbodyActivator : MonoBehaviour
3333
{
34-
[Tooltip("If this is checked then the collider will have it's rigidbody toggled on and off during a collision.")]
34+
[Tooltip("If this is checked then the Collider will have it's Rigidbody toggled on and off during a collision.")]
3535
public bool isEnabled = true;
36+
[Tooltip("If this is checked then the Rigidbody Activator will activate the rigidbody and colliders on the Interact Touch script.")]
37+
public bool activateInteractTouch = true;
38+
[Tooltip("If this is checked then the Rigidbody Activator will activate the rigidbody and colliders on the Controller Tracked Collider script.")]
39+
public bool activateTrackedCollider = false;
3640

3741
/// <summary>
3842
/// Emitted when the controller rigidbody is turned on.
@@ -71,11 +75,27 @@ protected virtual void OnTriggerExit(Collider collider)
7175

7276
protected virtual void ToggleRigidbody(Collider collider, bool state)
7377
{
74-
VRTK_InteractTouch touch = collider.GetComponentInParent<VRTK_InteractTouch>();
75-
if (touch != null && (isEnabled || !state))
78+
if (isEnabled || !state)
7679
{
77-
touch.ToggleControllerRigidBody(state, state);
78-
EmitEvent(state, touch);
80+
if (activateTrackedCollider)
81+
{
82+
VRTK_ControllerTrackedCollider trackedCollider = collider.GetComponentInParent<VRTK_ControllerTrackedCollider>();
83+
if (trackedCollider != null)
84+
{
85+
trackedCollider.ToggleColliders(state);
86+
EmitEvent(state, trackedCollider.interactTouch);
87+
}
88+
}
89+
90+
if (activateInteractTouch)
91+
{
92+
VRTK_InteractTouch touch = collider.GetComponentInParent<VRTK_InteractTouch>();
93+
if (touch != null)
94+
{
95+
touch.ToggleControllerRigidBody(state, state);
96+
EmitEvent(state, touch);
97+
}
98+
}
7999
}
80100
}
81101

Assets/VRTK/Source/Scripts/Interactions/Interactables/VRTK_IgnoreInteractTouchColliders.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace VRTK
44
using UnityEngine;
55
using System.Collections;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
/// <summary>
910
/// Ignores the collisions between the given Interact Touch colliders and the colliders on the GameObject this script is attached to.
@@ -98,6 +99,11 @@ protected virtual bool ShouldExclude(Transform checkObject)
9899
protected virtual void ManageTouchCollision(VRTK_InteractTouch touchToIgnore, bool ignore)
99100
{
100101
Collider[] interactTouchColliders = touchToIgnore.ControllerColliders();
102+
if (VRTK_ObjectCache.registeredTrackedColliderToInteractTouches.ContainsKey(touchToIgnore) && VRTK_ObjectCache.registeredTrackedColliderToInteractTouches[touchToIgnore] != null)
103+
{
104+
Collider[] trackedColliders = VRTK_ObjectCache.registeredTrackedColliderToInteractTouches[touchToIgnore].TrackedColliders();
105+
interactTouchColliders = interactTouchColliders.Concat(trackedColliders).ToArray();
106+
}
101107

102108
for (int touchCollidersIndex = 0; touchCollidersIndex < interactTouchColliders.Length; touchCollidersIndex++)
103109
{

Assets/VRTK/Source/Scripts/Interactions/Interactors/VRTK_ControllerHighlighter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Controller Highlighter|Interactors|30060
1+
// Controller Highlighter|Interactors|30070
22
namespace VRTK
33
{
44
using UnityEngine;

0 commit comments

Comments
 (0)