22class_name XRToolsDesktopMovementCrouch
33extends XRToolsMovementProvider
44
5-
65## XR Tools Movement Provider for Crouching
76##
87## This script works with the [XRToolsPlayerBody] attached to the players
@@ -11,7 +10,6 @@ extends XRToolsMovementProvider
1110## While the player presses the crounch button, the height is overridden to
1211## the specified crouch height.
1312
14-
1513## Enumeration of crouching modes
1614enum CrouchType {
1715 HOLD_TO_CROUCH , ## Hold button to crouch
@@ -20,46 +18,55 @@ enum CrouchType {
2018
2119
2220## Movement provider order
23- @export var order : int = 10
21+ @export var order : int = 10
2422
2523## Crouch height
26- @export var crouch_height : float = 1.0
24+ @export var crouch_height : float = 1.0
2725
2826## Crouch button
29- @export var crouch_button_action : String = "action_crouch"
27+ @export var crouch_button_action : String = "action_crouch"
3028
3129## Type of crouching
32- @export var crouch_type : CrouchType = CrouchType .HOLD_TO_CROUCH
30+ @export var crouch_type : CrouchType = CrouchType .HOLD_TO_CROUCH
3331
3432
3533## Crouching flag
36- var _crouching : bool = false
34+ var _crouching : bool = false
3735
3836## Crouch button down state
39- var _crouch_button_down : bool = false
37+ var _crouch_button_down : bool = false
4038
4139
42- # Controller node
43- @onready var xr_start_node = XRTools .find_xr_child (
44- XRTools .find_xr_ancestor (self ,
45- "*Staging" ,
46- "XRToolsStaging" ),"StartXR" ,"Node" )
40+ ## Controller node
41+ @onready var xr_start_node : XRToolsStartXR = XRTools .find_xr_child (
42+ XRTools .find_xr_ancestor (
43+ self ,
44+ "*Staging" ,
45+ "XRToolsStaging" ,
46+ ),
47+ "StartXR" ,
48+ "Node" ,
49+ )
4750
4851
49- # Add support for is_xr_class on XRTools classes
50- func is_xr_class (xr_name : String ) -> bool :
52+ ## Add support for is_xr_class on XRTools classes
53+ func is_xr_class (xr_name : String ) -> bool :
5154 return xr_name == "XRToolsMovementCrouch" or super (xr_name )
5255
5356
54- # Perform jump movement
55- func physics_movement (_delta : float , player_body : XRToolsPlayerBody , _disabled : bool ):
57+ ## Perform jump movement
58+ func physics_movement (
59+ _delta : float ,
60+ player_body : XRToolsPlayerBody ,
61+ _disabled : bool ,
62+ ) -> void :
5663 # Skip if the controller isn't active
57- if ! player_body .enabled or xr_start_node .is_xr_active ():
64+ if not player_body .enabled or xr_start_node .is_xr_active ():
5865 return
5966
6067 # Detect crouch button down and pressed states
6168 var crouch_button_down := Input .is_action_pressed (crouch_button_action )
62- var crouch_button_pressed := crouch_button_down and ! _crouch_button_down
69+ var crouch_button_pressed := crouch_button_down and not _crouch_button_down
6370 _crouch_button_down = crouch_button_down
6471
6572 # Calculate new crouching state
@@ -72,11 +79,12 @@ func physics_movement(_delta: float, player_body: XRToolsPlayerBody, _disabled:
7279 CrouchType .TOGGLE_CROUCH :
7380 # Toggle when button pressed
7481 if crouch_button_pressed :
75- crouching = ! crouching
82+ crouching = not crouching
7683
7784 # Update crouching state
7885 if crouching != _crouching :
7986 _crouching = crouching
87+
8088 if crouching :
8189 player_body .override_player_height (self , crouch_height )
8290 else :
0 commit comments