Zwischenversion
This commit is contained in:
parent
84b28968ec
commit
fbb880acd6
3 changed files with 32 additions and 22 deletions
|
|
@ -92,7 +92,6 @@ func change_player_area(id: int, area_key: String):
|
|||
rpc_id(id, "client_load_area", area_key)
|
||||
|
||||
# Avatar auf Server erstellen erfolgt erst wenn Client Vollzug meldet (client_ready_to_spawn)
|
||||
#_spawn_player_in_world(id, viewport_node)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func client_ready_to_spawn():
|
||||
|
|
@ -160,9 +159,11 @@ func _spawn_player_in_world(id, viewport_node):
|
|||
var player_scene = load("res://systems/player/player.tscn")
|
||||
var player = player_scene.instantiate()
|
||||
player.name = str(id)
|
||||
player.set_multiplayer_authority(id)
|
||||
|
||||
#player.set_multiplayer_authority(id)
|
||||
player.set_multiplayer_authority(1)
|
||||
|
||||
viewport_node.add_child(player)
|
||||
viewport_node.add_child(player, true)
|
||||
|
||||
# Visibility Filtering: Nur Spieler im gleichen Viewport sehen sich
|
||||
var sync = player.get_node("MultiplayerSynchronizer")
|
||||
|
|
@ -177,6 +178,10 @@ func _spawn_player_in_world(id, viewport_node):
|
|||
# Der alte Spieler sieht den neuen
|
||||
sync.set_visibility_for(other_id, true)
|
||||
|
||||
# Stelle sicher, dass der Spieler IMMER für seinen eigenen Client sichtbar ist.
|
||||
# Dies ist die wichtigste Regel, damit der Client seine eigenen Updates erhält.
|
||||
sync.set_visibility_for(id, true)
|
||||
|
||||
# Wir schicken dem Client eine Info, welchen Node er verfolgen soll
|
||||
# (Da der Name des Player-Nodes die ID ist, weiß der Client welcher seiner ist)
|
||||
rpc_id(id, "assign_camera_target", str(id))
|
||||
|
|
|
|||
|
|
@ -6,12 +6,6 @@
|
|||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ktl23"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_fqfg4"]
|
||||
properties/0/path = NodePath("CharacterBody3D:sync_position")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath("CharacterBody3D:sync_rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
|
||||
[node name="CharacterBody3D" type="CharacterBody3D" unique_id=682006733]
|
||||
script = ExtResource("1_ktl23")
|
||||
|
|
@ -28,7 +22,6 @@ shape = SubResource("CylinderShape3D_ktl23")
|
|||
root_node = NodePath("../..")
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="." unique_id=656518492]
|
||||
root_path = NodePath("../..")
|
||||
replication_interval = 0.05
|
||||
replication_config = SubResource("SceneReplicationConfig_fqfg4")
|
||||
public_visibility = false
|
||||
|
|
|
|||
|
|
@ -9,10 +9,13 @@ extends CharacterBody3D
|
|||
var path: PackedVector3Array = []
|
||||
var speed = 5.0
|
||||
|
||||
var _is_displayed=false
|
||||
|
||||
func _enter_tree():
|
||||
# Da der Name des Nodes die Peer-ID ist, setzen wir die Authority einfach selbst
|
||||
if name.is_valid_int():
|
||||
set_multiplayer_authority(name.to_int())
|
||||
#set_multiplayer_authority(name.to_int())
|
||||
set_multiplayer_authority(1)
|
||||
|
||||
func _ready():
|
||||
target_position = global_position
|
||||
|
|
@ -24,6 +27,8 @@ func _ready():
|
|||
func _physics_process(delta):
|
||||
# Dieser Teil läuft NUR auf dem Server
|
||||
if path.size() > 0:
|
||||
print("Server moving...")
|
||||
_is_displayed = false
|
||||
var next_point = path[0]
|
||||
var direction = (next_point - global_position).normalized()
|
||||
|
||||
|
|
@ -40,34 +45,39 @@ func _physics_process(delta):
|
|||
else:
|
||||
velocity = Vector3.ZERO
|
||||
sync_position = global_position # Sicherstellen, dass Standbild syncron bleibt
|
||||
|
||||
if _is_displayed == false:
|
||||
print("Target reached:", sync_position)
|
||||
_is_displayed = true
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func request_move(target: Vector3):
|
||||
if not multiplayer.is_server(): return
|
||||
|
||||
|
||||
#print("Server: Request Move received from client")
|
||||
|
||||
# Sicherheits-Check: Nur der Besitzer des Avatars darf ihn bewegen
|
||||
if multiplayer.get_remote_sender_id() != get_multiplayer_authority():
|
||||
return
|
||||
#if multiplayer.get_remote_sender_id() != get_multiplayer_authority():
|
||||
# return
|
||||
|
||||
# Hier später: path = astar.get_point_path(global_position, target)
|
||||
#path = PackedVector3Array([target])
|
||||
print("Target: ", target)
|
||||
print("Server Move to Target: ", target)
|
||||
path = [target]
|
||||
target_position = target
|
||||
|
||||
func _input(event):
|
||||
# NUR der Client, der diesen Spieler kontrolliert, darf klicken
|
||||
if not is_multiplayer_authority(): return
|
||||
#if not is_multiplayer_authority(): return
|
||||
if DisplayServer.get_name() == "headless": return # Server ignoriert Klicks
|
||||
|
||||
if multiplayer.is_server(): return # Kein Input vom Server
|
||||
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
print("Click")
|
||||
var target = _get_click_floor_pos()
|
||||
if target != Vector3.INF:
|
||||
print(" Request move")
|
||||
print(" ", target)
|
||||
print("Request move to target {0} by user {1}".format([target, name]))
|
||||
# RPC an den Server (ID 1)
|
||||
request_move.rpc_id(1, target)
|
||||
|
||||
|
|
@ -105,6 +115,8 @@ func _get_click_floor_pos():
|
|||
func _process(_delta):
|
||||
# Dieser Teil läuft auf dem Client (besonders dem, der die Authority hat)
|
||||
if not multiplayer.is_server():
|
||||
# Wir erzwingen die Position, die der Server berechnet hat
|
||||
global_position = sync_position
|
||||
rotation = sync_rotation
|
||||
if global_position != sync_position:
|
||||
print("Client: _process() => Setting client position")
|
||||
# Wir erzwingen die Position, die der Server berechnet hat
|
||||
global_position = sync_position
|
||||
rotation = sync_rotation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue