简体   繁体   English

如何使用高级多人游戏(ENET)在不同的坐标处生成两个节点?

[英]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.

相关问题 如何让敌人在 Godot 中生成并被吸引/旅行到 static 点? - How can I get enemies to spawn in Godot and be attracted/travel to a static point? 当我尝试生成多个节点时遇到一些信号问题 - I got some signal problems when I attempt to spawn multiple nodes 如何在godot中使用代码加入多人游戏? - How do I make a multiplayer game with code join in godot? 即使玩家在 Godot 中移动,如何将刚体 2d 节点吸引到玩家(使用点重力)? - How can I attract Rigidbody 2d nodes to the player (using point gravity) even when the player is moving in Godot? 如何使用旋转的相机将鼠标坐标投影到世界? - How can I project mouse coordinates to the world with a rotated camera? 如何让世界环境节点在进入区域节点时跨场景和场景之间连接信号以改变气氛 - How can i make world environment nodes connect with signals across and between scenes to change atmosphere when entering area nodes 如何比较godot中的两个节点坐标 - How to compare two node coordinates in godot 如何在 godot 中使用不同的脚本执行其他脚本? - How do I execute other scripts using a different script in godot? 如何查看构成场景的各个节点? - How do I view the individual nodes constituting a scene? 如何在 GDscript 中设置实例的 x 和 y 坐标 - How do i set the x and y coordinates of a instance in GDscript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM