0 votes

Hello. I trying to create simple air hockey game watching "Godot Over WebRTC! Using Nakama Matchmaking With Godot!" tutorial. To makes it easier, I decided to add my game over existing source code, because doing the other way around was too difficult for me. Here is my current version, where I cannot understand how to add shared and synced Puck object(RigidBody2D) for both players.

extends Node2D
export var player : PackedScene
#export var PuckShared : PackedScene
var ReadyPlayers = {}
func _ready():
    setupGame()
    pass # Replace with function body.

func setupGame():
    for id in GameManager.Players:
        var currentPlayer = player.instance()
#       var currentPuck = PuckShared.instance()
        currentPlayer.name = str(id)
        $PlayersSpawnUnder.add_child(currentPlayer)
#       $PlayersSpawnUnder.add_child(currentPuck)
        currentPlayer.set_network_master(GameManager.Players[id].peer_id)
        currentPlayer.position = get_node("SpawnPlayerPositions/" + str(GameManager.Players[id].peer_id)).position
#       PuckShared.position = get_node("SpawnPuck/3").position
#       $PlayersSpawnUnder.add_child(currentPuck)
#       PuckShared.position = get_node("SpawnPuck/3")
    var myID = OnlineMatch.get_my_session_id()
    var player = $PlayersSpawnUnder.get_node(str(myID))
    player.playerControlled = true
    rpc_id(1, "finishedSetup", myID)

Commented code in this image = my futile efforts to make it work.
My project in archive - link
If you need to test it directly you have to run local Nakama server via Docker Desktop and launch 2 game instances via enter image description here
Thanks for your attention!

Godot version 3.5.1
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.