Ввод: действия на физические клавиши (работает в любой раскладке)
W/A/S/D и стрелки, Пробел, Shift, C, Q — действия InputMap (move_*, jump, sprint, crouch, dash). Игрок использует их вместо is_key_pressed(KEY_*): на русской раскладке символ на клавише другой, а физическая клавиша та же. Сенсорные кнопки смогут нажимать те же действия. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-22
@@ -242,11 +242,10 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
head.rotate_x(-event.relative.y * MOUSE_SENSITIVITY * zoom_factor)
|
||||
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-80), deg_to_rad(80))
|
||||
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_C:
|
||||
_try_start_slide() # Подкат: бег (Shift) + C
|
||||
elif event.keycode == KEY_Q:
|
||||
_try_dash() # Рывок
|
||||
if event.is_action_pressed("crouch"):
|
||||
_try_start_slide() # Подкат: бег (sprint) + crouch
|
||||
elif event.is_action_pressed("dash"):
|
||||
_try_dash()
|
||||
|
||||
# Битовые флаги состояния для сетевой синхронизации (см. Net.FLAG_*)
|
||||
func get_net_flags() -> int:
|
||||
@@ -258,16 +257,8 @@ func get_net_flags() -> int:
|
||||
return flags
|
||||
|
||||
func _get_input_dir() -> Vector2:
|
||||
var input_dir := Vector2.ZERO
|
||||
if Input.is_key_pressed(KEY_D):
|
||||
input_dir.x += 1
|
||||
if Input.is_key_pressed(KEY_A):
|
||||
input_dir.x -= 1
|
||||
if Input.is_key_pressed(KEY_S):
|
||||
input_dir.y += 1
|
||||
if Input.is_key_pressed(KEY_W):
|
||||
input_dir.y -= 1
|
||||
return input_dir.normalized()
|
||||
# Действия привязаны к физическим клавишам (работает в любой раскладке); у них же — сенсорные кнопки
|
||||
return Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_dead:
|
||||
@@ -278,7 +269,7 @@ func _physics_process(delta: float) -> void:
|
||||
dash_cooldown_timer = maxf(dash_cooldown_timer - delta, 0.0)
|
||||
wallrun_cooldown_timer = maxf(wallrun_cooldown_timer - delta, 0.0)
|
||||
|
||||
var space_down := Input.is_key_pressed(KEY_SPACE)
|
||||
var space_down := Input.is_action_pressed("jump")
|
||||
|
||||
_update_crouch()
|
||||
|
||||
@@ -369,12 +360,12 @@ func _physics_process(delta: float) -> void:
|
||||
var current_speed := WALK_SPEED
|
||||
if is_crouching:
|
||||
current_speed = CROUCH_WALK_SPEED
|
||||
elif Input.is_key_pressed(KEY_SHIFT):
|
||||
elif Input.is_action_pressed("sprint"):
|
||||
current_speed = SPRINT_SPEED
|
||||
|
||||
# 4. Бег по стене
|
||||
if not is_wallrunning and not is_on_floor() and not is_sliding \
|
||||
and wallrun_cooldown_timer <= 0.0 and Input.is_key_pressed(KEY_W):
|
||||
and wallrun_cooldown_timer <= 0.0 and Input.is_action_pressed("move_forward"):
|
||||
_try_start_wallrun()
|
||||
if is_wallrunning:
|
||||
_process_wallrun(delta)
|
||||
@@ -565,7 +556,7 @@ func _process_wallrun(delta: float) -> void:
|
||||
var horiz := Vector3(velocity.x, 0, velocity.z)
|
||||
|
||||
if hit.is_empty() or wallrun_timer <= 0.0 or is_on_floor() \
|
||||
or not Input.is_key_pressed(KEY_W) \
|
||||
or not Input.is_action_pressed("move_forward") \
|
||||
or horiz.length() < WALLRUN_MIN_SPEED * 0.6:
|
||||
_end_wallrun()
|
||||
return
|
||||
@@ -716,7 +707,7 @@ func _try_start_slide() -> void:
|
||||
return
|
||||
if not is_on_floor():
|
||||
return
|
||||
if not Input.is_key_pressed(KEY_SHIFT):
|
||||
if not Input.is_action_pressed("sprint"):
|
||||
return
|
||||
|
||||
var horizontal := Vector3(velocity.x, 0, velocity.z)
|
||||
@@ -760,10 +751,10 @@ func _process_slide(delta: float, direction: Vector3, horizontal: Vector3) -> Ve
|
||||
func _update_crouch() -> void:
|
||||
var busy := is_sliding or is_dashing or is_wallrunning or is_mantling or not is_on_floor()
|
||||
if not is_crouching:
|
||||
if Input.is_key_pressed(KEY_C) and not busy:
|
||||
if Input.is_action_pressed("crouch") and not busy:
|
||||
is_crouching = true
|
||||
_set_collider_crouched(true)
|
||||
elif (busy or not Input.is_key_pressed(KEY_C)) and (is_sliding or _can_stand()):
|
||||
elif (busy or not Input.is_action_pressed("crouch")) and (is_sliding or _can_stand()):
|
||||
_end_crouch()
|
||||
|
||||
func _end_crouch() -> void:
|
||||
|
||||
Reference in New Issue
Block a user