如何使用高级多人游戏 (ENET) 在不同的坐标生成两个节点?
How can I spawn two nodes at different coordinates using High Level Multiplayer (ENET)?
目前,我正在使用带有 Godot 的高级多人游戏 (ENET) 来生成两个玩家节点(使用 KinematicBody2D 和 Collisions)。由于碰撞导致问题的原因,我不能让玩家在相同的坐标中生成,所以我试图让他们彼此相邻生成。
我把我的 Player.gd 放在这个 pastebin link 上,它有我要调试的代码。
我遇到的问题是试图让客户端和服务器在我在玩家场景初始化时设置的坐标处生成玩家。目前,客户端和服务器可以正确定位自己,但另一个玩家在 (0,0) 处闲逛,直到我移动玩家。
播放器移动完美无缺,因此即使该代码在粘贴中,也与此问题无关。
客户端的标准输出是
Connecting to Server!!!
Player Connected!!!
Network Master: 151057035
Player ID: 151057035
Client Position - Master: 151057035
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 0
Network Master: 1
Player ID: 151057035
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Player: 1 Set Position: (300, 250)
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 1
服务器的标准输出是
Hosting Server!!!
Player Connected!!!
Network Master: 1
Player ID: 1
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 0
Network Master: 959488417
Player ID: 1
Client Position - Master: 959488417
Player: 959488417 Set Position: (500, 250)
Player: 959488417 Set Position: (500, 250)
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 959488417
基本上,要告诉客户端在什么坐标生成,您需要让服务器告诉客户端使用什么坐标。
我自己的个人代码涉及玩家注册和追踪,所以直接贴完整代码太复杂了。相反,我发布了一个大大简化的生成代码(甚至不包括多世界支持)
示例代码
# Server Code
master func spawn_server(net_id: int, coordinates: Vector2):
rpc_unreliable_id(net_id, "spawn", coordinates) # Godot's RPC handles ensuring packet delivery just like TCP, but with less overhead.
# Client Code in Same File
puppet func spawn(coordinates: Vector2):
player_object.position = coordinates
目前,我正在使用带有 Godot 的高级多人游戏 (ENET) 来生成两个玩家节点(使用 KinematicBody2D 和 Collisions)。由于碰撞导致问题的原因,我不能让玩家在相同的坐标中生成,所以我试图让他们彼此相邻生成。
我把我的 Player.gd 放在这个 pastebin link 上,它有我要调试的代码。
我遇到的问题是试图让客户端和服务器在我在玩家场景初始化时设置的坐标处生成玩家。目前,客户端和服务器可以正确定位自己,但另一个玩家在 (0,0) 处闲逛,直到我移动玩家。
播放器移动完美无缺,因此即使该代码在粘贴中,也与此问题无关。
客户端的标准输出是
Connecting to Server!!!
Player Connected!!!
Network Master: 151057035
Player ID: 151057035
Client Position - Master: 151057035
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 0
Network Master: 1
Player ID: 151057035
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Player: 1 Set Position: (300, 250)
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 1
服务器的标准输出是
Hosting Server!!!
Player Connected!!!
Network Master: 1
Player ID: 1
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 0
Network Master: 959488417
Player ID: 1
Client Position - Master: 959488417
Player: 959488417 Set Position: (500, 250)
Player: 959488417 Set Position: (500, 250)
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 959488417
基本上,要告诉客户端在什么坐标生成,您需要让服务器告诉客户端使用什么坐标。
我自己的个人代码涉及玩家注册和追踪,所以直接贴完整代码太复杂了。相反,我发布了一个大大简化的生成代码(甚至不包括多世界支持)
示例代码
# Server Code
master func spawn_server(net_id: int, coordinates: Vector2):
rpc_unreliable_id(net_id, "spawn", coordinates) # Godot's RPC handles ensuring packet delivery just like TCP, but with less overhead.
# Client Code in Same File
puppet func spawn(coordinates: Vector2):
player_object.position = coordinates