improve multiplayer controller movement

This commit is contained in:
Teatov 2025-02-27 21:41:08 +10:00
parent b180fab115
commit e290a3afcd
2 changed files with 18 additions and 12 deletions

View File

@ -72,25 +72,25 @@ toggle_fullscreen={
]
}
move_up={
"deadzone": 0.5,
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
]
}
move_left={
"deadzone": 0.5,
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
]

View File

@ -19,9 +19,10 @@ var _move_down: float
func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
if mode == Inputer.Mode.KB_MOUSE:
if event is not InputEventKey:
return
if Referencer.players_count == 1:
return
if mode == Inputer.Mode.KB_MOUSE and event is InputEventKey:
var key_event := event as InputEventKey
if key_event.is_action_pressed("move_left"):
_move_left = 1
@ -40,11 +41,16 @@ func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
elif key_event.is_action_released("move_down"):
_move_down = 0
if mode == Inputer.Mode.CONTROLLER:
_move_left = Input.get_action_raw_strength("move_left")
_move_right = Input.get_action_raw_strength("move_right")
_move_up = Input.get_action_raw_strength("move_up")
_move_down = Input.get_action_raw_strength("move_down")
if mode == Inputer.Mode.CONTROLLER and event is InputEventJoypadMotion:
var motion_event := event as InputEventJoypadMotion
if motion_event.is_action("move_left"):
_move_left = motion_event.get_action_strength("move_left")
if motion_event.is_action("move_right"):
_move_right = motion_event.get_action_strength("move_right")
if motion_event.is_action("move_up"):
_move_up = motion_event.get_action_strength("move_up")
if motion_event.is_action("move_down"):
_move_down = motion_event.get_action_strength("move_down")
func movement(