@@ -69,6 +69,8 @@ const Ecctrl: ForwardRefRenderFunction<CustomEcctrlRigidBody, EcctrlProps> = ({
69
69
camTargetPos = { x : 0 , y : 0 , z : 0 } ,
70
70
camMoveSpeed = 1 ,
71
71
camZoomSpeed = 1 ,
72
+ leftJoystickDeadZoneThreshold = 0 ,
73
+ rightJoystickDeadZoneThreshold = 0 ,
72
74
camCollision = true ,
73
75
camCollisionOffset = 0.7 ,
74
76
camCollisionSpeedMult = 4 ,
@@ -511,10 +513,16 @@ const Ecctrl: ForwardRefRenderFunction<CustomEcctrlRigidBody, EcctrlProps> = ({
511
513
}
512
514
}
513
515
516
+ const applyDeadZone = ( value : number , threshold : number ) => {
517
+ return Math . abs ( value ) > threshold ? value : 0 ;
518
+ }
519
+
514
520
const handleSticks = ( axes : readonly number [ ] ) => {
521
+ const adjustedLeftStickX = applyDeadZone ( axes [ 0 ] , leftJoystickDeadZoneThreshold ) ;
522
+ const adjustedLeftStickY = applyDeadZone ( axes [ 1 ] , leftJoystickDeadZoneThreshold ) ;
515
523
// Gamepad first joystick trigger the EcctrlJoystick event to move the character
516
- if ( Math . abs ( axes [ 0 ] ) > 0 || Math . abs ( axes [ 1 ] ) > 0 ) {
517
- gamepadJoystickVec2 . set ( axes [ 0 ] , - axes [ 1 ] )
524
+ if ( Math . abs ( adjustedLeftStickX ) > 0 || Math . abs ( adjustedLeftStickY ) > 0 ) {
525
+ gamepadJoystickVec2 . set ( adjustedLeftStickX , - adjustedLeftStickY )
518
526
gamepadJoystickDis = Math . min ( Math . sqrt ( Math . pow ( gamepadJoystickVec2 . x , 2 ) + Math . pow ( gamepadJoystickVec2 . y , 2 ) ) , 1 )
519
527
gamepadJoystickAng = gamepadJoystickVec2 . angle ( )
520
528
const runState = gamepadJoystickDis > 0.7
@@ -524,9 +532,11 @@ const Ecctrl: ForwardRefRenderFunction<CustomEcctrlRigidBody, EcctrlProps> = ({
524
532
gamepadJoystickAng = 0
525
533
resetJoystick ( )
526
534
}
535
+ const adjustedRightStickX = applyDeadZone ( axes [ 2 ] , rightJoystickDeadZoneThreshold ) ;
536
+ const adjustedRightStickY = applyDeadZone ( axes [ 3 ] , rightJoystickDeadZoneThreshold ) ;
527
537
// Gamepad second joystick trigger the useFollowCam event to move the camera
528
- if ( Math . abs ( axes [ 2 ] ) > 0 || Math . abs ( axes [ 3 ] ) > 0 ) {
529
- joystickCamMove ( axes [ 2 ] , axes [ 3 ] )
538
+ if ( Math . abs ( adjustedRightStickX ) > 0 || Math . abs ( adjustedRightStickY ) > 0 ) {
539
+ joystickCamMove ( adjustedRightStickX , adjustedRightStickY ) ;
530
540
}
531
541
}
532
542
@@ -1566,6 +1576,8 @@ export interface EcctrlProps extends RigidBodyProps {
1566
1576
camTargetPos ?: { x : number , y : number , z : number } ;
1567
1577
camMoveSpeed ?: number ;
1568
1578
camZoomSpeed ?: number ;
1579
+ leftJoystickDeadZoneThreshold ?: number ;
1580
+ rightJoystickDeadZoneThreshold ?: number ;
1569
1581
camCollision ?: boolean ;
1570
1582
camCollisionOffset ?: number ;
1571
1583
camCollisionSpeedMult ?: number ;
0 commit comments