Git Product home page Git Product logo

godot-multiplayer-template's People

Contributors

corinnaj avatar leonmatthes avatar mariusdoe avatar phkeese avatar tom95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

godot-multiplayer-template's Issues

Syncing Spatial Camera

How can I properly sync Spatial Camera which is a child of a kinematic body?

This is what my Player.tscn looks like:
image

The issue:
camera-issue

I tried doing a few things like adding "camera" into the unrealiable-sync field (cuz I reference it in my player controller script), also tried adjusting node hierarchy for player to make it work somehow but I ended up with a bunch of errors if I move the Sync anywhere else in the Players.tscn

Allow choosing server vs. game mode via code

Starting the entire application with a command line flag to distinguish between server and client is tedious and locks in that instance of the application to the chosen mode.

Instead, it should be possible to choose the mode via code. Perhaps a Singleton would do the trick, something like Multiplayer.start_server(port: int, player_count: int) and Multiplayer.join_server(port: int, ip: String) for hosting and joining,

I am not sure how I would go about implementing this, but maybe get_tree().change_scene_to() would be helpful.

Allow passing custom parameters to clients launched from editor button

I want to be able to pass additional parameters to server and client upon starting the game.
Godot features a built-in way to pass arguments via the project setting editor/main_run_args but I want even finer control and only pass some arguments to the client.

Use case: I want to use a controller for input but Godot detects input from joysticks even when the game is not in focus. This makes testing quite pointless, as both client and server move on their own. I want to specify which controller to use with a command line argument.

How to implement: I would suggest another project setting editor/main_run_args.client for arguments passed to the clients and using the regular editor/main_run_args as server arguments

Edit: If this is implemented, it would be smart to also implement the normal %command% syntax.

Feedback after Game Jam

First off, thanks for providing the template, it was really helpful to get started.

sync.tscn

  • Generally works well
  • Should try to update the position, but if the object does not have a position (i.e. Node subclass), it should simply skip that step (
    Or just do: export (PoolStringArray) var synced_properties = ['position']
  • Note: If setget is used for an attribute, both rset and sync.tscn will call the setter, which is very useful!

game.gd

  • Add command-line argument for IP+port (default to localhost)
  • Otherwise worked pretty reliably

Structure of game.tscn

Instead of the current structure of:

  • game
    • 1 (Server player)
    • 1234567 (client player)
    • my_level_object1
    • my_level_object2
      I want to propose the following structure:
  • game
    • camera (Camera2D)
    • level (Node, level_switch.gd)
      • level1 (level1.tscn)
      • 1 (Server player)
      • 12345 (Client player)
      • sync (sync.tscn)
    • clients
      • 1 (Node, or similar)
      • 12345 (Node, or similar)

Initial implementation of level_switch.gd

extends Node

var level_path: String setget set_level_path

# Called when the node enters the scene tree for the first time.
func _ready():
	rset_config('level_path', MultiplayerAPI.RPC_MODE_REMOTESYNC)

func set_level(new_path: String):
	rset('level_path', new_path)

func set_level_path(new_path: String):
	level_path = new_path
	for child in get_children():
		# take care to not delete the sync component
		if child.name != 'sync':
			self.remove_child(child)
			child.queue_free()
		
	var new_level = load(new_path).instance()
	add_child(new_level)

In the initalization of game.gd, you can then just call:

$level.set_level('res://level/level.tscn')

To load any custom level you want.

This should of course be done before auto-creating the players.

The advantage of adding the level as a subnode of the game is of course, that it can be switched really easily.
If players can die, it also makes a lot of sense to decouple player + client, so that for each connected client, a client node exists, but not necessarily a player (i.e. player is dead atm.)
This is also helpful when changing levels, as the entire level including players can just be deleted and for each node under $clients, a new player can be created.

For example, this is my code to switch levels in game.gd:

func switch_level(level_path: String):
	$level.set_level(level_path)
	
	for player_id in $clients.get_children():
		spawn_new_player(player_id.id)
	register_main()

spawn_new_player basically boils down to:

func spawn_new_player():
	var new_player = register_player(player_id, null, {})
	
        # Do some game logic to figure initialize the new player
	
	rpc("register_player", player_id, new_player.position, new_player.get_sync_state())

Then _ready can just be:

        # ..... Create, the network peer, but do not! create any players!
        get_tree().set_network_peer(peer)
	
	if not is_client:
		if not is_dedicated:
			register_player_id(1)
		switch_level('res://level/my_level.tscn')

Does this template still work?

Hey, I'm new to Godot and I was looking for some networking plugins and I came about this template, I tried setting it up according to the steps in README but was having a few errors, I would like to know if this is still active and works with latest stable Godot thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.