Search Unity

Instantiating new players, or just representations of the players?

Discussion in 'Connected Games' started by Velcrohead, Mar 12, 2015.

  1. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    72
    Afternoon all,

    So I've been trying to come to terms with basic networking principles (however it's definitely not what I first though), and I'm still stuck with one thing which is confusing me.

    In a networked game, as a player joins, should a new 'player' be instantiated, or just a representation of that player which responds to their actions / positioning and stuff.

    I would imagine that it's the latter, as the former could get complicated(?), but the tutorials I've been following, have always instantiated a new player object as each player joins.

    Sorry if this isn't very clear, it's been a long day and I'm still trying to wrap my head around it before diving into anything too deep.

    Thanks in advance,
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    With Unity's networking, you almost certainly want to instantiate an object on the client machine, and let Unity replicate that instantiation over the network, and use that object to drive the visual representation of the player.

    However, there are going to be some operations that you don't want to perform on remote shadows (sometimes called duplicas) of the object - things like input handling, HUD interaction, anything that you only want to perform locally on the machine that owns the object. There may also be some things you only want to do remotely, like cut-down versions of some behaviours - perhaps you use a different strategy for driving animations remotely.

    There are a few ways to handle those cases - you could write your scripts so that they check at various points whether the object is locally-owned, or you could attach different scripts initially depending upon whether the object is local or not, or you could defer all this dependent processing to another gameobject and instantiate it as a child of the networked object. You can decide which way to go, and you can mix and match these techniques too. The easiest way to begin with at least is to just add conditionals to your scripts where necessary.
     
unityunity