Skip to content

Commit

Permalink
feat(Pointer): add direction indicator touchpad deadzone
Browse files Browse the repository at this point in the history
The Pointer Direction Indicator now has a `touchpad deadzone`
setting that prevents the direction indicator being rotated if
the touchpad is being touched within the deadzone.

This is useful if the direction indicator doesn't want to be activated
within a specific threshold on the touchpad (or thumbstick) axis.
  • Loading branch information
thestonefox committed Aug 14, 2017
1 parent fd3ad03 commit 5ed3ccf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public enum VisibilityState
AlwaysOnWithPointerCursor
}

[Header("Control Settings")]
[Tooltip("The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle.")]
public Vector2 touchpadDeadzone = Vector2.zero;

[Header("Appearance Settings")]

[Tooltip("If this is checked then the reported rotation will include the offset of the headset rotation in relation to the play area.")]
Expand Down Expand Up @@ -125,12 +129,17 @@ protected virtual void Awake()

protected virtual void Update()
{
if (controllerEvents != null && controllerEvents.touchpadTouched && controllerEvents.GetTouchpadAxis() != Vector2.zero)
if (controllerEvents != null && controllerEvents.touchpadTouched && !InsideDeadzone(controllerEvents.GetTouchpadAxis()))
{
float touchpadAngle = controllerEvents.GetTouchpadAxisAngle();
float angle = ((touchpadAngle > 180) ? touchpadAngle -= 360 : touchpadAngle) + headset.eulerAngles.y;
transform.localEulerAngles = new Vector3(0f, angle, 0f);
}
}

protected virtual bool InsideDeadzone(Vector2 currentAxis)
{
return (currentAxis == Vector2.zero || (Mathf.Abs(currentAxis.x) <= touchpadDeadzone.x && Mathf.Abs(currentAxis.y) <= touchpadDeadzone.y));
}
}
}
1 change: 1 addition & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ This can be useful for rotating the play area upon teleporting to face the user

### Inspector Parameters

* **Touchpad Deadzone:** The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle.
* **Include Headset Offset:** If this is checked then the reported rotation will include the offset of the headset rotation in relation to the play area.
* **Display On Invalid Location:** If this is checked then the direction indicator will be displayed when the location is invalid.
* **Use Pointer Color:** If this is checked then the pointer valid/invalid colours will also be used to change the colour of the direction indicator.
Expand Down

0 comments on commit 5ed3ccf

Please sign in to comment.