Skip to content

Commit 6fa5d5b

Browse files
committed
feat(Locomotion): add option to only touchpad walk on button press
A new option has been added to the Touchpad Walking script that allows a button to be specified for enabling movement. Only when that button is being pressed will the touchpad walking actually move the user. The Controller Events script has also been updated to allow for this with a new public method that checks to see if a given button alias is being pressed.
1 parent 13dba64 commit 6fa5d5b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Assets/VRTK/Scripts/VRTK_ControllerEvents.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,35 @@ public bool AnyButtonPressed()
619619
return (triggerPressed || gripPressed || touchpadPressed || applicationMenuPressed);
620620
}
621621

622+
/// <summary>
623+
/// The IsButtonPressed method takes a given button alias and returns a boolean whether that given button is currently being pressed or not.
624+
/// </summary>
625+
/// <param name="button">The button to check if it's being pressed.</param>
626+
/// <returns>Is true if the button is being pressed.</returns>
627+
public bool IsButtonPressed(ButtonAlias button)
628+
{
629+
switch (button)
630+
{
631+
case ButtonAlias.Trigger_Hairline:
632+
return triggerHairlinePressed;
633+
case ButtonAlias.Trigger_Touch:
634+
return triggerTouched;
635+
case ButtonAlias.Trigger_Press:
636+
return triggerPressed;
637+
case ButtonAlias.Trigger_Click:
638+
return triggerClicked;
639+
case ButtonAlias.Grip:
640+
return grabPressed;
641+
case ButtonAlias.Touchpad_Touch:
642+
return touchpadTouched;
643+
case ButtonAlias.Touchpad_Press:
644+
return touchpadPressed;
645+
case ButtonAlias.Application_Menu:
646+
return applicationMenuPressed;
647+
}
648+
return false;
649+
}
650+
622651
private ControllerInteractionEventArgs SetButtonEvent(ref bool buttonBool, bool value, float buttonPressure)
623652
{
624653
buttonBool = value;

Assets/VRTK/Scripts/VRTK_TouchpadWalking.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public bool RightController
4545
public float maxWalkSpeed = 3f;
4646
[Tooltip("The speed in which the play area slows down to a complete stop when the user is no longer touching the touchpad. This deceleration effect can ease any motion sickness that may be suffered.")]
4747
public float deceleration = 0.1f;
48+
[Tooltip("If a button is defined then movement will only occur when the specified button is being held down and the touchpad axis changes.")]
49+
public VRTK_ControllerEvents.ButtonAlias moveOnButtonPress = VRTK_ControllerEvents.ButtonAlias.Undefined;
4850

4951
private GameObject controllerLeftHand;
5052
private GameObject controllerRightHand;
@@ -76,6 +78,12 @@ private void Start()
7678

7779
private void DoTouchpadAxisChanged(object sender, ControllerInteractionEventArgs e)
7880
{
81+
var controllerEvents = (VRTK_ControllerEvents)sender;
82+
if (moveOnButtonPress != VRTK_ControllerEvents.ButtonAlias.Undefined && !controllerEvents.IsButtonPressed(moveOnButtonPress))
83+
{
84+
touchAxis = Vector2.zero;
85+
return;
86+
}
7987
touchAxis = e.touchpadAxis;
8088
}
8189

DOCUMENTATION.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ The GetHairTriggerDelta method returns a float representing the difference in ho
629629

630630
The AnyButtonPressed method returns true if any of the controller buttons are being pressed and this can be useful to determine if an action can be taken whilst the user is using the controller.
631631

632+
#### IsButtonPressed/1
633+
634+
> `public bool IsButtonPressed(ButtonAlias button)`
635+
636+
* Parameters
637+
* `ButtonAlias button` - The button to check if it's being pressed.
638+
* Returns
639+
* `bool` - Is true if the button is being pressed.
640+
641+
The IsButtonPressed method takes a given button alias and returns a boolean whether that given button is currently being pressed or not.
642+
632643
### Example
633644

634645
`VRTK/Examples/002_Controller_Events` shows how the events are utilised and listened to. The accompanying example script can be viewed in `VRTK/Examples/Resources/Scripts/VRTK_ControllerEvents_ListenerExample.cs`.
@@ -1431,6 +1442,7 @@ If the Headset Collision Fade script has been applied to the Camera prefab, then
14311442

14321443
* **Max Walk Speed:** The maximum speed the play area will be moved when the touchpad is being touched at the extremes of the axis. If a lower part of the touchpad axis is touched (nearer the centre) then the walk speed is slower.
14331444
* **Deceleration:** The speed in which the play area slows down to a complete stop when the user is no longer touching the touchpad. This deceleration effect can ease any motion sickness that may be suffered.
1445+
* **Move On Button Press:** If a button is defined then movement will only occur when the specified button is being held down and the touchpad axis changes.
14341446

14351447
### Example
14361448

0 commit comments

Comments
 (0)