Godot Version
4.4.1
Question
Im trying to make the server spawn bullets on the clients.
The bullets are spawning on the server but not showing on the clients.
in the Player script i do, that is requesting the server to spawn a bullet:
func _process(_delta):
if !is_multiplayer_authority():
return
if Input.is_action_just_pressed("ui_fire"):
main.rpc_id(1, "server_shoot_bullet", multiplayer.get_unique_id(), username,
on the server in the Main script i do this, that is calling an rpc “remote”:
@rpc(“any_peer”, “call_remote”)
func server_shoot_bullet(pid, username, position, shoot_direction):
$BulletSpawner.spawn(pid)
func spawn_bullet(pid, username, position, shoot_direction):
if !multiplayer.is_server():
return
print(“pid: %d - Server is spawning a bullet - Request by: %s” % [multiplayer.get_unique_id(), username])
var bullet = bullet_scene.instantiate()
bullet.global_position = Vector2(500, 500)
bullet.set_launch_direction(shoot_direction)
bullet.set_shooting_player_username(username)
$Bullets.add_child(bullet)
return bullet
I thought i should use “call_remote” only so that the clients can use this function signature in their rpc calls?
The BulletSpawner has spawn_path set to “Bullets” in the tree.
Im very new to multiplayer in godot so i haven’t fully grasped the concepts of rpc’s and the multiplayerSpawner.
The player’s are spawning correctly when the MultiplayerSpawner calls it spawnfunction on client_connect though.
What i wan’t to achive is:
- Player press ‘f’ - calls rpc_id with ‘1’ so that the BulletSpawner.spawn() function is called on the server.
- Server spawns a bullet on all clients with parameters passed in the rpc.
there’s also a prolem the paramters, how do i pass multiple paramters to the MutliplayerSpawner.spawn() function when the spawn_function is assign a function with multiple parameters?