[英]How can I spawn two nodes at different coordinates using High Level Multiplayer (ENET)?
Currently, I am using High Level Multiplayer (ENET) with Godot to spawn two player nodes (with KinematicBody2D and Collisions). 目前,我正在使用Godot的High Level Multiplayer(ENET)生成两个玩家节点(带有KinematicBody2D和Collisions)。 For reasons of collisions causing problems, I cannot have the players spawn in the same coordinates, so I am trying to get them to spawn next to each other.
由于碰撞导致问题的原因,我不能让玩家在相同的坐标处生成,因此我试图让它们彼此相邻生成。
I put my Player.gd on this pastebin link which has the code I am trying to debug. 我将Player.gd放在该pastebin链接上,该链接具有我要调试的代码。
The problem I am having is trying to get the client and server to spawn the players at the coordinates I have set in the initialization of the player scene. 我遇到的问题是试图让客户端和服务器在播放器场景的初始化中设置的坐标处生成播放器。 Currently, the client and server can position themselves correctly, but the other player hangs out at (0,0) until I move the player.
当前,客户端和服务器可以正确定位自己的位置,但是其他播放器在(0,0)处挂出,直到我移动播放器为止。
The player movement works perfectly, so even though that code is in the paste, it isn't relevant to this question. 播放器运动效果很好,因此即使粘贴了该代码,它也与该问题无关。
The client's stdout is 客户端的标准输出是
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
The server's stdout is 服务器的标准输出为
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
Basically, to tell the client what coordinates to spawn at, you need to have the server tell the client what coordinates to use. 基本上,要告诉客户端生成什么坐标,您需要让服务器告诉客户端要使用什么坐标。
My own personal code involves player registration and tracking, so it is too complicated to just paste the full code. 我自己的个人代码涉及玩家注册和跟踪,因此仅粘贴完整代码太复杂了。 Instead, I am posting a greatly simplified spawn code (that does not even include multi-world support)
相反,我发布了一个大大简化的生成代码(甚至不包括多世界支持)
Sample Code 样例代码
# 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.