#MultiplayerSpawner, giving all peers authority to instantiate scenes

9 messages · Page 1 of 1 (latest)

pine obsidian
#

Hello, I am tying to create a small multiplayer scene where I have players firing projectiles but I am having some problems.

Currently I have setup a MultiplayerSpawner node which has a player scene as well as a projectile scene added to its auto spawn list. Both the player scene and projectile scene have a MultiplayerSynchronizer node which synchronizes the position and rotation.

I have successfully gotten two players into the scene on both clients, including movement and rotation.

My issue is that whenever I try to create the projectiles, when the host fires a projectile it is also replicated on the client but when the client fires a projectile it is not replicated on the host. I assume this is related to the following:

"Auto Spawn List: Defines the scenes to be automatically replicated when added as a child of spawn_path by the authority (server by default)."
found at: https://godotengine.org/article/multiplayer-in-godot-4-0-scene-replication/#spawning-and-despawning-scenes

Since only only the scenes added by the host (server) would be replicated by default.

The post also says:
"You can use the set_multiplayer_authority() method to control which peer is allowed to instantiate scenes via the spawner (the server by default)."

but I don't see how this could solve my issue since giving the authority to the client instead of the host would from what I understand just cause the same issue in reverse, that the client could spawn scenes on both the client and the host but the host would then only be able to spawn scenes on the host.

Is there a way to allow all peers to have authority to instantiate scenes?

I understand that allowing all peers to have authority might be a problem if the clients can't be trusted but that's not a issue to worry about in my case. However if there are any resources or if anyone could help out to explain how it's done, I would be glad to hear.

Godot Engine

Create multiplayer games in an instance (pun intended) with the new MultiplayerSpawner and MultiplayerSynchronizer nodes. Check out the key concepts, and get started with a quick tutorial on how to make a simple game using Godot multiplayer features!

pine obsidian
#

Here's some further images to show how I set it up:

Projectile related code in Player script:

...
func _unhandled_input(event):
    if not is_multiplayer_authority(): return
    if Input.is_action_just_pressed("shoot"):
        spawn_projectile()
...
func spawn_projectile():
    var projectile = Projectile.instantiate()
    
    projectile.transform = projectile_spawn.global_transform
    projectile.velocity = -projectile.transform.basis.z * projectile.FIRE_VELOCITY
    
    projectile.set_multiplayer_authority(str(name).to_int())
    projectile.name = "Projectile_" + str(name) + "_"
    
    get_parent().add_child(projectile, true) # parent = "World" node
...
#

Main scene setup:

#

MultiplayerSpawner setup:

#

MultiplayerSynchronizer for projectile setup:

uneven granite
#

What about adding a MultiplayerSpawner as a child of each player to handle that players projectiles?

pine obsidian
#

Can I more than one MultiplayerSpawner?
And would this not mean that I had to have the projectiles as children of the player as well?
Which would cause the player movement to be applied to the projectile

uneven granite
#

You can have more than one spawner, and you can specify the spawners path, so they all spawn the projectiles properly, not as children to the player.

pine obsidian
#

Alright, I'll give it a try. Thank you!