@@ -57,6 +57,9 @@ export class InputManager {
5757 }
5858
5959 initVRControls ( onSessionStart , onSessionEnd ) {
60+ // Determiniamo quale mano spara
61+ const fireHand = CURRENT_SETTINGS . leftHanded ? 'left' : 'right' ;
62+
6063 for ( let i = 0 ; i < 2 ; i ++ ) {
6164 const controller = this . renderer . xr . getController ( i ) ;
6265
@@ -66,23 +69,26 @@ export class InputManager {
6669
6770 if ( xrInputSource . handedness === 'right' ) {
6871 this . rightController = controller ;
69- if ( this . renderer . xr . isPresenting && onSessionStart ) {
70- onSessionStart ( ) ;
71- }
7272 } else if ( xrInputSource . handedness === 'left' ) {
7373 this . leftController = controller ;
7474 }
75+
76+ // Avvia la sessione quando viene connesso il controller che impugna l'arma
77+ if ( xrInputSource . handedness === fireHand && this . renderer . xr . isPresenting && onSessionStart ) {
78+ onSessionStart ( ) ;
79+ }
7580 } ) ;
7681
82+ // Ascoltiamo il grilletto sulla mano che spara
7783 controller . addEventListener ( 'selectstart' , ( ) => {
78- if ( controller . handedness === 'right' ) {
84+ if ( controller . handedness === fireHand ) {
7985 this . isTriggerDown = true ;
8086 this . triggerPressedThisFrame = true ;
8187 }
8288 } ) ;
8389
8490 controller . addEventListener ( 'selectend' , ( ) => {
85- if ( controller . handedness === 'right' ) {
91+ if ( controller . handedness === fireHand ) {
8692 this . isTriggerDown = false ;
8793 }
8894 } ) ;
@@ -104,16 +110,19 @@ export class InputManager {
104110 inputX = Number ( this . moveState . right ) - Number ( this . moveState . left ) ;
105111 } else if ( this . renderer . xr . isPresenting ) {
106112 const session = this . renderer . xr . getSession ( ) ;
113+ const moveHand = CURRENT_SETTINGS . leftHanded ? 'right' : 'left' ;
114+ const turnHand = CURRENT_SETTINGS . leftHanded ? 'left' : 'right' ;
115+
107116 if ( session && session . inputSources ) {
108117 for ( const source of session . inputSources ) {
109118 if ( source . gamepad && source . gamepad . axes . length >= 4 ) {
110- if ( source . handedness === 'left' ) {
119+ if ( source . handedness === moveHand ) {
111120 const xAxis = source . gamepad . axes [ 2 ] ;
112121 const zAxis = source . gamepad . axes [ 3 ] ;
113122 if ( Math . abs ( xAxis ) > 0.1 ) inputX = xAxis ;
114123 if ( Math . abs ( zAxis ) > 0.1 ) inputZ = - zAxis ;
115124 }
116- else if ( source . handedness === 'right' ) {
125+ else if ( source . handedness === turnHand ) {
117126 const turnAxis = source . gamepad . axes [ 2 ] ;
118127 if ( Math . abs ( turnAxis ) > 0.1 ) {
119128 this . playerRig . rotation . y -= turnAxis * CURRENT_SETTINGS . turnSpeed * delta ;
@@ -126,7 +135,6 @@ export class InputManager {
126135 }
127136 }
128137 }
129-
130138 return { inputX, inputZ } ;
131139 }
132140
0 commit comments