Merge multiplayer_spawner and lobby-map into develop #3
@@ -39,6 +39,8 @@ func _ready() -> void:
|
||||
multiplayer.connection_failed.connect(_on_connection_failed)
|
||||
|
||||
check_command_line()
|
||||
|
||||
multiplayer.server_relay = true
|
||||
|
||||
func _process(delta):
|
||||
if not steam_initialized:
|
||||
@@ -153,7 +155,7 @@ func spawn_player(peer_id: int):
|
||||
add_child(new_player)
|
||||
new_player.position = Vector3.UP
|
||||
new_player.set_player_name(player_name)
|
||||
new_player.set_multiplayer_authority(peer_id)
|
||||
new_player.set_multiplayer_authority(peer_id, true)
|
||||
new_player.setup_player()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://csmfxg011xisf"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://csmfxg011xisf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dopyfulbw2mx5" path="res://player/player.gd" id="1_ulp21"]
|
||||
|
||||
@@ -13,17 +13,6 @@ size = Vector3(0.5, 0.5, 0.5)
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_wnvi2"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ulp21"]
|
||||
properties/0/path = NodePath(".:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath(".:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
properties/2/path = NodePath("Label3D:text")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 2
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
@@ -62,9 +51,6 @@ layers = 2
|
||||
mesh = SubResource("SphereMesh_wnvi2")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_ulp21")
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.887858, 0)
|
||||
billboard = 1
|
||||
|
||||
@@ -8,7 +8,6 @@ class_name Player
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
var camera_node: Camera3D
|
||||
|
||||
|
||||
func setup_player():
|
||||
if is_multiplayer_authority():
|
||||
print("-> [%s] Authority granted. Setting up camera and input." % name)
|
||||
@@ -22,34 +21,40 @@ func set_player_name(player_name: String):
|
||||
$Label3D.text = player_name
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if !is_multiplayer_authority():
|
||||
return
|
||||
# Apply gravity
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
@rpc("any_peer", "call_local", "unreliable")
|
||||
func update_remote_transform(new_transform: Transform3D):
|
||||
global_transform = new_transform
|
||||
|
||||
# Handle Jump
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = jump_velocity
|
||||
|
||||
# Get the input direction and apply movement
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
func _physics_process(delta):
|
||||
if is_multiplayer_authority():
|
||||
# Apply gravity
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
# Handle Jump
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = jump_velocity
|
||||
|
||||
# Get the input direction and apply movement
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
velocity.z = move_toward(velocity.z, 0, speed)
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
velocity.z = move_toward(velocity.z, 0, speed)
|
||||
else:
|
||||
# Air control
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 5.0)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 5.0)
|
||||
|
||||
move_and_slide()
|
||||
# Air control
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 5.0)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 5.0)
|
||||
move_and_slide()
|
||||
|
||||
update_remote_transform.rpc("unreliable", global_transform)
|
||||
|
||||
|
||||
func _input(event):
|
||||
if !is_multiplayer_authority():
|
||||
|
||||
Reference in New Issue
Block a user