despawn runner or chaser on disconnect
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
extends MultiplayerSynchronizer
|
||||
|
||||
@export var direction: Vector2 = Vector2.ZERO
|
||||
@export var walking: bool = false
|
||||
@export var walk: bool = false
|
||||
@export var primary_interact: bool = false
|
||||
@export var secondary_interact: bool = false
|
||||
|
||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||
|
||||
@@ -9,10 +11,9 @@ func _ready() -> void:
|
||||
if multiplayer.is_server() or get_multiplayer_authority() != multiplayer.get_unique_id():
|
||||
set_process(false)
|
||||
set_physics_process(false)
|
||||
return
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var directional_input := Input.get_vector("move_right", "move_left", "move_forward", "move_back")
|
||||
var camera_adjusted: Vector3 = (directional_input.x * _camera_pivot.global_basis.z) + (directional_input.y * _camera_pivot.global_basis.x)
|
||||
direction = Vector2(camera_adjusted.x, camera_adjusted.z).rotated(PI / 2.0).normalized()
|
||||
walking = Input.is_action_pressed("walk")
|
||||
walk = Input.is_action_pressed("walk")
|
||||
|
||||
@@ -26,9 +26,8 @@ func _ready() -> void:
|
||||
get_tree().change_scene_to_packed.call_deferred(main_menu_scene)
|
||||
|
||||
func connect_to_ip(runner: bool = true, ip: String = "") -> void:
|
||||
if ip.is_empty():
|
||||
ip = IP_ADDRESS
|
||||
|
||||
if ip.is_empty(): ip = IP_ADDRESS
|
||||
|
||||
runner_client_selection = runner
|
||||
|
||||
print("Connecting to: %s" % ip)
|
||||
@@ -46,25 +45,23 @@ func _on_connect(id: int) -> void:
|
||||
|
||||
func _on_disconnect(id: int) -> void:
|
||||
print("Client ID #%s disconnected" % id)
|
||||
pass
|
||||
if not multiplayer.is_server(): return
|
||||
|
||||
get_tree().get_current_scene().despawn_player(id)
|
||||
|
||||
func _on_connect_client() -> void:
|
||||
request_is_runner.rpc_id(1, runner_client_selection)
|
||||
print("[%s] Connected to server" % multiplayer.get_unique_id())
|
||||
pass
|
||||
|
||||
func _on_disconnect_client() -> void:
|
||||
print("[%s] Disconnected" % multiplayer.get_unique_id())
|
||||
pass
|
||||
|
||||
func _on_server_closed_client() -> void:
|
||||
print("[%s] Server closed" % multiplayer.get_unique_id())
|
||||
pass
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func request_is_runner(runner: bool) -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
if not multiplayer.is_server(): return
|
||||
|
||||
var id := multiplayer.get_remote_sender_id()
|
||||
runner_dict[id] = runner
|
||||
|
||||
Reference in New Issue
Block a user