Skip to content

Commit

Permalink
feat(Controller): add trigger click threshold parameter
Browse files Browse the repository at this point in the history
It's now possible to specify the click threshold that the trigger axis
must exceed for a click to be registered.

The reason for this is, the trigger click should happen when the axis
has reached it's maximum level of 1f but this is achieved by a
microswitch inside the controller trigger being pressed and when it is
pressed it changes the trigger axis to 1f. However, if the controller
microswitch is broken and not registering the click then the trigger
axis is never set to 1f and therefore the trigger click event is never
emitted. This setting gives the ability to reduce the threshold to a
level where a click even can still be recognised on faulty hardware.
  • Loading branch information
thestonefox committed Aug 22, 2016
1 parent bd3e7d0 commit a5d31da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Assets/VRTK/Examples/002_Controller_Events.unity
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ MonoBehaviour:
uiClickButton: 3
menuToggleButton: 7
axisFidelity: 1
triggerClickThreshold: 1
triggerPressed: 0
triggerTouched: 0
triggerHairlinePressed: 0
Expand Down Expand Up @@ -401,6 +402,7 @@ MonoBehaviour:
uiClickButton: 3
menuToggleButton: 7
axisFidelity: 1
triggerClickThreshold: 1
triggerPressed: 0
triggerTouched: 0
triggerHairlinePressed: 0
Expand Down
5 changes: 3 additions & 2 deletions Assets/VRTK/Scripts/VRTK_ControllerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ButtonAlias
public ButtonAlias menuToggleButton = ButtonAlias.Application_Menu;

public int axisFidelity = 1;
public float triggerClickThreshold = 1f;

[HideInInspector]
public bool triggerPressed = false;
Expand Down Expand Up @@ -629,12 +630,12 @@ private void Update()
}

//Trigger Clicked
if (!triggerClicked && currentTriggerAxis.x == 1f)
if (!triggerClicked && currentTriggerAxis.x >= triggerClickThreshold)
{
OnTriggerClicked(SetButtonEvent(ref triggerClicked, true, currentTriggerAxis.x));
EmitAlias(ButtonAlias.Trigger_Click, true, currentTriggerAxis.x, ref triggerClicked);
}
else if (triggerClicked && currentTriggerAxis.x < 1f)
else if (triggerClicked && currentTriggerAxis.x < triggerClickThreshold)
{
OnTriggerUnclicked(SetButtonEvent(ref triggerClicked, false, 0f));
EmitAlias(ButtonAlias.Trigger_Click, false, 0f, ref triggerClicked);
Expand Down
1 change: 1 addition & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ The script also has a public boolean pressed state for the buttons to allow the
* **UI Click Button:** The button to use for the action of clicking a UI element.
* **Menu Toggle Button:** The button to use for the action of bringing up an in-game menu.
* **Axis Fidelity:** The amount of fidelity in the changes on the axis, which is defaulted to 1. Any number higher than 2 will probably give too sensitive results.
* **Trigger Click Threshold:** The level on the trigger axis to reach before a click is registered.

### Class Variables

Expand Down

0 comments on commit a5d31da

Please sign in to comment.