Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiplayer asteroids field problems

Discussion in 'Multiplayer' started by Amateria, Nov 25, 2015.

  1. Amateria

    Amateria

    Joined:
    Oct 14, 2014
    Posts:
    3
    Hi everybody,

    First, i'm a french guy, sorry for my english.

    I'm on a personal project of a simple multiplayer game that takes place in space.
    I've already set up the multiplayer part, players can control their own ship driven by physic.

    I'm writing scripts to spawn an asteroids field and some questions came to me.
    My goal is to allow player to "mine" theses asteroid with a weapon and a raycast.

    Asteroids will have a script with a synced var like "amountRemaining". they are spawned by a script who run OnStartServer function

    Actualy the server instantiate and spawn a given number of "asteroids" on random position
    Asteroids is a cube with a networkidentity and is referenced as spawnable gameobject.

    This seams to work correctly but the question is : is that the good way to do things ? I mean, with a network identity on every asteroids ?

    And i got problems about parent/child hierarchy over the network. I can figure out the way to spawn chieldren objects in the clients.
    In this way, does it's better to have only one object with a network identity (asteroidsField) that can synced there childs (asteroids) ?

    Thanks you for you awnsers and for reading me !
     
  2. Amateria

    Amateria

    Joined:
    Oct 14, 2014
    Posts:
    3
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    You should actually experiment with this. We don't know how many asteroids you plan. It sound like there could be a lot but who knows?
    In multiplayer games, it always makes a difference how many entities you have and how much you need to sync for each. This doesn't only apply to the question "how many players do you have?".
    If you have a few asteroids: nevermind. Use a network identity for each. If you have some in regions, use a identity per region.
     
  4. Amateria

    Amateria

    Joined:
    Oct 14, 2014
    Posts:
    3
    Hi,

    Thanks for the reply.

    There will be 1-8 or a few more players

    For me it's a personal training project and i want to learn the logicals ways to builds things in a multiplayer game.
    I'm building the basics of the world and try to sync it with the clients.

    [EDIT] I want to say that i don't know how many asteroid the game can handle. i will set the "density" of asteroids regarding the way i choose to do things and how this way can handle asteroids

    So, if i listen to you, if i want 1000 asteroids, it's a better way to make a thing like an asteroid manager, the only thing with a network identity.
    The server own this asteroids manager and create the list of asteroids and call rpc on client to instantiate them from a prefab (without using the "spawn" function) and the server can have other rpc that he can call to update/destroy asteroids on client

    This sounds like each clients must have there own local list of asteroids provided by the server at the connection.

    Does it's sounds good ?
     
    Last edited: Dec 2, 2015
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    There are lots of ways to achieve the (more or less) same thing.
    I wouldn't use RPCs per asteroid.
    The manager is a good idea. It could determine which asteroids are of interest per player and send them the values. It could send a bunch of asteroids in one message, too.
    Make the asteroid info as lean as possible. If you place all asteroids in a scene, you could assign an ID to each and then you only have to send messages that say "asteroid 100 has X ore". Of course, you should not send this as text ;)