@@ -877,6 +877,49 @@ export function initGamepad() {
877877 const gamepad = gamepads [ 0 ] ; // Use the first connected gamepad
878878
879879 if ( gamepad ) {
880+ // Handle analog sticks like dpad
881+ const threshold = 0.5 ;
882+ const leftStickX = gamepad . axes [ 0 ] ;
883+ const leftStickY = gamepad . axes [ 1 ] ;
884+
885+ // Left stick horizontal (left/right)
886+ if ( leftStickX < - threshold ) {
887+ if ( ! buttonStates [ 'leftStickLeft' ] ) {
888+ buttonStates [ 'leftStickLeft' ] = true ;
889+ handleGameControllerButtonPress ( 14 ) ; // Left
890+ }
891+ } else if ( buttonStates [ 'leftStickLeft' ] ) {
892+ buttonStates [ 'leftStickLeft' ] = false ;
893+ }
894+
895+ if ( leftStickX > threshold ) {
896+ if ( ! buttonStates [ 'leftStickRight' ] ) {
897+ buttonStates [ 'leftStickRight' ] = true ;
898+ handleGameControllerButtonPress ( 15 ) ; // Right
899+ }
900+ } else if ( buttonStates [ 'leftStickRight' ] ) {
901+ buttonStates [ 'leftStickRight' ] = false ;
902+ }
903+
904+ // Left stick vertical (up/down)
905+ if ( leftStickY < - threshold ) {
906+ if ( ! buttonStates [ 'leftStickUp' ] ) {
907+ buttonStates [ 'leftStickUp' ] = true ;
908+ handleGameControllerButtonPress ( 12 ) ; // Up
909+ }
910+ } else if ( buttonStates [ 'leftStickUp' ] ) {
911+ buttonStates [ 'leftStickUp' ] = false ;
912+ }
913+
914+ if ( leftStickY > threshold ) {
915+ if ( ! buttonStates [ 'leftStickDown' ] ) {
916+ buttonStates [ 'leftStickDown' ] = true ;
917+ handleGameControllerButtonPress ( 13 ) ; // Down
918+ }
919+ } else if ( buttonStates [ 'leftStickDown' ] ) {
920+ buttonStates [ 'leftStickDown' ] = false ;
921+ }
922+
880923 [ 0 , 1 , 2 , 3 , 4 , 5 , 8 , 12 , 13 , 14 , 15 ] . forEach ( ( buttonIndex ) => {
881924 const button = gamepad . buttons [ buttonIndex ] ;
882925 const wasPressed = buttonStates [ buttonIndex ] ;
0 commit comments