Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Tinkering with the Multiplayer Viking Demo

Discussion in 'Multiplayer' started by KlausAidon, Sep 1, 2012.

  1. KlausAidon

    KlausAidon

    Joined:
    Aug 1, 2012
    Posts:
    11
    I'm currently tinkering, and trying to learn how to use the Multiplayer viking demo. I'm trying to figure out how it works, so I can set it to use in my own game, and I have a few questions that I would really appreciate help with.

    One of the first things I'm trying, is setting the demo inside a different scene. I downloaded the "Medieval Village" scene from the asset store, and I'm trying to set the game to work in that scene. It works, for the most part, but with a few hiccups. The first was the log in screen staring at the sky, but I fixed that with a quick alteration to where the log in camera looks. But what I'm having trouble with is that the player is "spawning" underneath the terrain, and thus falling into the void. I can pause unity, and pull the model back up above the Terrain, so I was able to find it wasn't a collision detection issue as the model walks around in the environment just fine (Although is a bit small). So I need to know how to get the model to spawn above the terrain. I've been poking through all the files, and just can't find what class sets where the viking spawns. Does anyone know what file I should look at? Also, if I were to want to change the genre of this game, say, to a 2.5D platform game, where would I go about tinkering with/replacing to change this? I already have a 2.5D platform game made that I would like to import this into.

    And while I'm at this, I'd also appreciate any hints on using a different model for the player. I haven't tried this yet, but if anyone has tried it themselves, and would like to give me some hints/warnings, I would appreciate the help. My knowledge on 3D modeling is a lot weaker than coding, and I've mostly been using free models I find in the asset store.

    Thanks!
     
  2. MaarX

    MaarX

    Joined:
    Jul 26, 2012
    Posts:
    39
    This is a great resource to get you started, it tells you everything:

    http://doc.exitgames.com/photon-cloud/Marco_Polo_Tutorial/#_Toc317517585

    As for the spawning, I think there is a gameObject with a script: GameManager attached to it. Just move that object to the spawning position where you want to spawn.

    The above tutorial will explain everything you need to get started. New models etc. It helped me!
     
  3. KlausAidon

    KlausAidon

    Joined:
    Aug 1, 2012
    Posts:
    11
    Thanks, I fixed the spawning, and the reference you provided was pretty helpful, however it left some questions.

    I'm having trouble with using different models. Simply put, when I try to use a different model, references to scripts get broken, and the guide doesn't explain how to fix them. Would be helpful if the guide explained how to get the player model working from scratch, instead of relying on prebuilt assets. I would be fine just having a simple cube avatars walking around.
     
  4. MaarX

    MaarX

    Joined:
    Jul 26, 2012
    Posts:
    39
    Create a cube gameobject, attach a photonview script to it (misc > photonview), create a new script, call it networkcube or whatever, add the following:
    Code (csharp):
    1.  
    2.     private Vector3 correctPos;
    3.     void Update ()
    4.     {
    5.             transform.position = Vector3.Lerp (transform.position, correctPos, Time.deltaTime * 5);
    6.     }
    7.    
    8.     void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
    9.     {
    10.         if (stream.isWriting) {
    11.             stream.SendNext (transform.position);
    12.         } else {
    13.             correctPos = (Vector3)stream.ReceiveNext ();
    14.         }
    15.     }
    16.  
    Attach the script to your cube, then set the photonView to observe this script. It will basically smooth your cube movement across all clients.

    You can also set the photonView to observe the cube, this will show the location of the cube etc, but not smoothed.

    I believe marco polo talks about this. Except it uses a preset model, but that could be a cube, it doesnt matter.

    By the way, don't forget to add some movement controls, besides the scripts I just talked about*
     
  5. KlausAidon

    KlausAidon

    Joined:
    Aug 1, 2012
    Posts:
    11
    Ok, this is a start. I also attached the third person controller, and camera, along with a rigidbody, but now the cube is falling through the Terrain. Any idea what I could be doing wrong?
     
  6. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    Maybe you need a collider on ground. Perhaps on the char too. Viking uses capsule collider
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    As far as learning material goes, the Viking Demo is not the best start. I need to make that more obvious in that demo, cause here I'm clearly a bit late.
    The early steps are probably best taken with the Marco Polo Tutorial, which you can work through step by step, too:
    http://doc.exitgames.com/photon-cloud/Marco_Polo_Tutorial

    It seems you are now at a point where other pieces are missing.
    Hope you're now making the progress you want to.