change _input to _unhandled_input in most classes
This commit is contained in:
parent
26fe3ae790
commit
c57c724f0a
@ -50,7 +50,7 @@ func _process(_delta: float) -> void:
|
||||
_control.queue_redraw()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("toggle_debug"):
|
||||
mode = wrapi(mode + 1, 0, Mode.size()) as Mode
|
||||
_update_visibility()
|
||||
|
||||
@ -5,7 +5,7 @@ func _ready() -> void:
|
||||
Referencer.main_loaded.connect(_on_referencer_main_loaded)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("toggle_cursor_capture"):
|
||||
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
@ -22,6 +22,9 @@ var _peer_id: int = 1
|
||||
var _respawn_point: Vector3
|
||||
var _default_camera_height: float
|
||||
|
||||
var _crouch: bool = false
|
||||
var _run: bool = false
|
||||
|
||||
@onready var _camera: Camera3D = $Camera3D
|
||||
@onready var _name_label: Label3D = $NameLabel
|
||||
|
||||
@ -76,8 +79,6 @@ func _physics_process(delta: float) -> void:
|
||||
_lateral_movement(delta)
|
||||
_vertical_movement(delta)
|
||||
|
||||
_jumping(delta)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
@ -85,9 +86,24 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
if event is InputEventMouseMotion:
|
||||
_handle_mouse_rotating(event as InputEventMouseMotion)
|
||||
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
|
||||
return
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
_handle_mouse_rotating(event as InputEventMouseMotion)
|
||||
|
||||
if event.is_action_pressed("jump"):
|
||||
_jump()
|
||||
|
||||
if event.is_action_pressed("crouch"):
|
||||
_crouch = true
|
||||
if event.is_action_released("crouch"):
|
||||
_crouch = false
|
||||
|
||||
if event.is_action_pressed("run"):
|
||||
_run = true
|
||||
if event.is_action_released("run"):
|
||||
_run = false
|
||||
|
||||
|
||||
func set_info(player_info: Dictionary) -> void:
|
||||
@ -136,14 +152,14 @@ func _process_controller_rotating(delta: float) -> void:
|
||||
|
||||
func _process_camera(delta: float) -> void:
|
||||
var camera_height := _default_camera_height
|
||||
if Input.is_action_pressed("crouch"):
|
||||
if _crouch:
|
||||
camera_height = CAMERA_CROUCH_HEIGHT
|
||||
_camera.position.y = move_toward(
|
||||
_camera.position.y, camera_height, CAMERA_HEIGHT_SPEED * delta
|
||||
)
|
||||
|
||||
var camera_fov := Settings.camera_fov
|
||||
if Input.is_action_pressed("run"):
|
||||
if _run:
|
||||
camera_fov += CAMERA_RUN_EXTRA_FOV
|
||||
_camera.fov = move_toward(_camera.fov, camera_fov, CAMERA_FOV_SPEED * delta)
|
||||
|
||||
@ -152,7 +168,9 @@ func _lateral_movement(delta: float) -> void:
|
||||
var input_dir := Input.get_vector(
|
||||
"move_left", "move_right", "move_forward", "move_back"
|
||||
)
|
||||
var has_input := input_dir.length() > 0
|
||||
var has_input := (
|
||||
input_dir.length() > 0 and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
|
||||
)
|
||||
|
||||
if has_input:
|
||||
var direction := (
|
||||
@ -160,10 +178,10 @@ func _lateral_movement(delta: float) -> void:
|
||||
)
|
||||
var speed := MOVE_SPEED
|
||||
Debugger.text("move_mode", "move", 2)
|
||||
if Input.is_action_pressed("crouch"):
|
||||
if _crouch:
|
||||
speed = CROUCH_SPEED
|
||||
Debugger.text("move_mode", "crouch", 2)
|
||||
if Input.is_action_pressed("run"):
|
||||
if _run:
|
||||
speed = RUN_SPEED
|
||||
Debugger.text("move_mode", "run", 2)
|
||||
var new_velocity := direction * speed
|
||||
@ -184,11 +202,6 @@ func _vertical_movement(delta: float) -> void:
|
||||
velocity.y = 0
|
||||
|
||||
|
||||
func _jumping(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = JUMP_FORCE
|
||||
|
||||
|
||||
func _handle_mouse_rotating(event: InputEventMouseMotion) -> void:
|
||||
var sensitivity := deg_to_rad(Settings.mouse_sensitivity)
|
||||
|
||||
@ -210,6 +223,11 @@ func _handle_mouse_rotating(event: InputEventMouseMotion) -> void:
|
||||
_camera.rotation.x = clamp(_camera.rotation.x, -PI / 2, PI / 2)
|
||||
|
||||
|
||||
func _jump() -> void:
|
||||
if is_on_floor():
|
||||
velocity.y = JUMP_FORCE
|
||||
|
||||
|
||||
func _on_networker_player_registered(peer_id: int, player_info: Dictionary) -> void:
|
||||
if peer_id != _peer_id:
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user