0

目前,我正在使用带有 Godot 的高级多人游戏 (ENET) 来生成两个玩家节点(使用 KinematicBody2D 和碰撞)。由于碰撞导致问题的原因,我不能让玩家在相同的坐标中产卵,所以我试图让它们彼此相邻产卵。

我把我的 Player.gd 放在这个pastebin 链接上,它有我要调试的代码。

我遇到的问题是试图让客户端和服务器在我在玩家场景初始化时设置的坐标处生成玩家。目前,客户端和服务器可以正确定位自己,但其他玩家在 (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
4

1 回答 1

0

基本上,要告诉客户端生成的坐标,您需要让服务器告诉客户端使用什么坐标。

我自己的个人代码涉及玩家注册和跟踪,所以粘贴完整代码太复杂了。相反,我发布了一个大大简化的生成代码(甚至不包括多世界支持)


示例代码

# 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
于 2019-08-05T00:37:42.917 回答