@@ -14,11 +14,17 @@ namespace HoloToolkit.Unity.InputModule
1414 [ RequireComponent ( typeof ( SetGlobalListener ) ) ]
1515 public class MixedRealityTeleport : Singleton < MixedRealityTeleport > , IControllerInputHandler
1616 {
17- [ Tooltip ( "Name of the joystick axis to move along X ." ) ]
18- public string LeftJoystickX = "ControllerLeftStickX" ;
17+ [ Tooltip ( "Name of the thumbstick axis to check for teleport and strafe ." ) ]
18+ public string LeftThumbstickX = "ControllerLeftStickX" ;
1919
20- [ Tooltip ( "Name of the joystick axis to move along Y." ) ]
21- public string LeftJoystickY = "ControllerLeftStickY" ;
20+ [ Tooltip ( "Name of the thumbstick axis to check for teleport and strafe." ) ]
21+ public string LeftThumbstickY = "ControllerLeftStickY" ;
22+
23+ [ Tooltip ( "Name of the thumbstick axis to check for rotation." ) ]
24+ public string RightThumbstickX = "ControllerRightStickX" ;
25+
26+ [ Tooltip ( "Name of the thumbstick axis to check for rotation." ) ]
27+ public string RightThumbstickY = "ControllerRightStickY" ;
2228
2329 public bool EnableTeleport = true ;
2430 public bool EnableRotation = true ;
@@ -78,51 +84,51 @@ private void HandleGamepad()
7884 {
7985 if ( EnableTeleport && ! fadeControl . Busy )
8086 {
81- float leftX = Input . GetAxis ( "ControllerLeftStickX" ) ;
82- float leftY = Input . GetAxis ( "ControllerLeftStickY" ) ;
87+ float leftX = Input . GetAxis ( LeftThumbstickX ) ;
88+ float leftY = Input . GetAxis ( LeftThumbstickY ) ;
8389
84- if ( currentPointingSource == null && leftY > 0.8 && Math . Abs ( leftX ) < 0.2 )
90+ if ( currentPointingSource == null && leftY > 0.8 && Math . Abs ( leftX ) < 0.3 )
8591 {
8692 if ( FocusManager . Instance . TryGetSinglePointer ( out currentPointingSource ) )
8793 {
8894 StartTeleport ( ) ;
8995 }
9096 }
91- else if ( currentPointingSource != null && Math . Sqrt ( Math . Pow ( leftX , 2 ) + Math . Pow ( leftY , 2 ) ) < 0.1 )
97+ else if ( currentPointingSource != null && new Vector2 ( leftX , leftY ) . magnitude < 0.2 )
9298 {
9399 FinishTeleport ( ) ;
94100 }
95101 }
96102
97103 if ( EnableStrafe && currentPointingSource == null && ! fadeControl . Busy )
98104 {
99- float leftX = Input . GetAxis ( "ControllerLeftStickX" ) ;
100- float leftY = Input . GetAxis ( "ControllerLeftStickY" ) ;
105+ float leftX = Input . GetAxis ( LeftThumbstickX ) ;
106+ float leftY = Input . GetAxis ( LeftThumbstickY ) ;
101107
102- if ( leftX < - 0.8 && Math . Abs ( leftY ) < 0.2 )
108+ if ( leftX < - 0.8 && Math . Abs ( leftY ) < 0.3 )
103109 {
104110 DoStrafe ( Vector3 . left * StrafeAmount ) ;
105111 }
106- else if ( leftX > 0.8 && Math . Abs ( leftY ) < 0.2 )
112+ else if ( leftX > 0.8 && Math . Abs ( leftY ) < 0.3 )
107113 {
108114 DoStrafe ( Vector3 . right * StrafeAmount ) ;
109115 }
110- else if ( leftY < - 0.8 && Math . Abs ( leftX ) < 0.2 )
116+ else if ( leftY < - 0.8 && Math . Abs ( leftX ) < 0.3 )
111117 {
112118 DoStrafe ( Vector3 . back * StrafeAmount ) ;
113119 }
114120 }
115121
116122 if ( EnableRotation && currentPointingSource == null && ! fadeControl . Busy )
117123 {
118- float rightX = Input . GetAxis ( "ControllerRightStickX" ) ;
119- float rightY = Input . GetAxis ( "ControllerRightStickY" ) ;
124+ float rightX = Input . GetAxis ( RightThumbstickX ) ;
125+ float rightY = Input . GetAxis ( RightThumbstickY ) ;
120126
121- if ( rightX < - 0.8 && Math . Abs ( rightY ) < 0.2 )
127+ if ( rightX < - 0.8 && Math . Abs ( rightY ) < 0.3 )
122128 {
123129 DoRotation ( - RotationSize ) ;
124130 }
125- else if ( rightX > 0.8 && Math . Abs ( rightY ) < 0.2 )
131+ else if ( rightX > 0.8 && Math . Abs ( rightY ) < 0.3 )
126132 {
127133 DoRotation ( RotationSize ) ;
128134 }
@@ -131,39 +137,42 @@ private void HandleGamepad()
131137
132138 void IControllerInputHandler . OnInputPositionChanged ( InputPositionEventData eventData )
133139 {
134- if ( EnableTeleport )
140+ if ( eventData . PressType == InteractionSourcePressType . Thumbstick )
135141 {
136- if ( currentPointingSource == null && eventData . Position . y > 0.8 && Math . Abs ( eventData . Position . x ) < 0.2 )
142+ if ( EnableTeleport )
137143 {
138- if ( FocusManager . Instance . TryGetPointingSource ( eventData , out currentPointingSource ) )
144+ if ( currentPointingSource == null && eventData . Position . y > 0.8 && Math . Abs ( eventData . Position . x ) < 0.3 )
139145 {
140- currentSourceId = eventData . SourceId ;
141- StartTeleport ( ) ;
146+ if ( FocusManager . Instance . TryGetPointingSource ( eventData , out currentPointingSource ) )
147+ {
148+ currentSourceId = eventData . SourceId ;
149+ StartTeleport ( ) ;
150+ }
151+ }
152+ else if ( currentPointingSource != null && currentSourceId == eventData . SourceId && eventData . Position . magnitude < 0.2 )
153+ {
154+ FinishTeleport ( ) ;
142155 }
143156 }
144- else if ( currentPointingSource != null && currentSourceId == eventData . SourceId && eventData . Position . magnitude < 0.1 )
145- {
146- FinishTeleport ( ) ;
147- }
148- }
149157
150- if ( EnableStrafe && currentPointingSource == null )
151- {
152- if ( eventData . Position . y < - 0.8 && Math . Abs ( eventData . Position . x ) < 0.2 )
158+ if ( EnableStrafe && currentPointingSource == null )
153159 {
154- DoStrafe ( Vector3 . back * StrafeAmount ) ;
160+ if ( eventData . Position . y < - 0.8 && Math . Abs ( eventData . Position . x ) < 0.3 )
161+ {
162+ DoStrafe ( Vector3 . back * StrafeAmount ) ;
163+ }
155164 }
156- }
157165
158- if ( EnableRotation && currentPointingSource == null )
159- {
160- if ( eventData . Position . x < - 0.8 && Math . Abs ( eventData . Position . y ) < 0.2 )
161- {
162- DoRotation ( - RotationSize ) ;
163- }
164- else if ( eventData . Position . x > 0.8 && Math . Abs ( eventData . Position . y ) < 0.2 )
166+ if ( EnableRotation && currentPointingSource == null )
165167 {
166- DoRotation ( RotationSize ) ;
168+ if ( eventData . Position . x < - 0.8 && Math . Abs ( eventData . Position . y ) < 0.3 )
169+ {
170+ DoRotation ( - RotationSize ) ;
171+ }
172+ else if ( eventData . Position . x > 0.8 && Math . Abs ( eventData . Position . y ) < 0.3 )
173+ {
174+ DoRotation ( RotationSize ) ;
175+ }
167176 }
168177 }
169178 }
0 commit comments