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

GTGD's Unity Multiplayer Tutorials

Discussion in 'Community Learning & Teaching' started by GTGD, Feb 7, 2012.

?

Please select each option you agree with (you can select multiple options)

Poll closed Dec 22, 2015.
  1. I like that the videos are covering a complete project.

    230 vote(s)
    88.1%
  2. I find the videos are detailed enough for me to understand and follow.

    197 vote(s)
    75.5%
  3. I find the video quality is clear enough.

    186 vote(s)
    71.3%
  4. I find the audio quality is clear enough.

    180 vote(s)
    69.0%
  5. The narrator doesn't send me to sleep.

    143 vote(s)
    54.8%
  6. In general the topics covered are interesting.

    170 vote(s)
    65.1%
  7. I find the website useful.

    130 vote(s)
    49.8%
  8. The Gamer To Game Developer logo looks good.

    119 vote(s)
    45.6%
  9. I would like to suggest topics that GTGD should cover in the future.

    103 vote(s)
    39.5%
Multiple votes are allowed.
  1. Shmixil

    Shmixil

    Joined:
    May 25, 2015
    Posts:
    2
    Thanks for the fix! Unfortunately, I ran into another problem. It's not as critical as the last one and you probably experience it too, but if I do a full 360, the controls are reversed. In both as an .exe and in the simulation in Unity.
     
  2. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Nope never experienced that. I think you'll have to go and watch the video again because it sounds like you might have gotten your axes mixed up.
     
  3. King_ZZ

    King_ZZ

    Joined:
    Jun 21, 2015
    Posts:
    2
    Last edited: Jul 4, 2015
  4. Srooney193

    Srooney193

    Joined:
    Oct 27, 2015
    Posts:
    4
    Hi first of all I just want to thank you on how much you have helped me you are great at what you do and should keep up the good work.
    I,m completely new to game developing and i have followed everything you have done but when i try run the game is tells me that.........

    UnityEngine3.up' cannot be accessed with an instant reference, qualify it with a type name instead.

    And the other problem is I followed every step for the script for the Fire Blaster but when i select the player then press components--->Script--->and there is no scrip for the fire blaster, just terrain, Blaster and the camera.

    If anyone can please help me with this as i am trying so hard to fix it and continue learning to develope games would be very much appritiated.

    Thank you.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There is no place anyone would write UnityEngine3.up. I would suggest you look more carefully at the code. It could be autocomplete wrongly completed that for you.
     
  6. Srooney193

    Srooney193

    Joined:
    Oct 27, 2015
    Posts:
    4
    Sorry I meant UnityEngine.Vector3.up' is the error and I have checked the coding and I dont see what I have done wrong.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// This script is attached to the blaster projectile and it
    6. /// governs the behavior of the projectile.
    7. /// </summary>
    8.  
    9. public class BlasterScript : MonoBehaviour {
    10.  
    11.     //Variable Start___________________________________
    12.  
    13.     // A quick refference.
    14.  
    15.     private Transform myTransform;
    16.  
    17.  
    18.     //The projectiles flight speed.
    19.  
    20.     private float projectileSpeed = 10;
    21.  
    22.  
    23.     //Prevent the projectile from causing
    24.     //further harm once it has hit something.
    25.  
    26.     private bool expended = false;
    27.  
    28.  
    29.     //A ray projected in front of the projectile
    30.     //to see if it will hit a recognisable collider.
    31.  
    32.     private RaycastHit hit;
    33.  
    34.  
    35.     //The range of that ray.
    36.  
    37.     private float range = 1.5f;
    38.  
    39.  
    40.     //The life span of the projectile.
    41.  
    42.     private float expireTime = 5;
    43.  
    44.  
    45.     //Variable End_____________________________________
    46.  
    47.     // Use this for initialization
    48.     void Start ()
    49.     {
    50.         myTransform = transform;
    51.    
    52.         //As soon as the projectile is created start a countdown
    53.         //to destroy it.
    54.    
    55.         StartCoroutine(DestroyMyselfAfterSomeTime());
    56.     }
    57.  
    58.     // Update is called once per frame
    59.     void Update ()
    60.     {
    61.         //Translate the projectile in the up direction (the pointed
    62.         //end of the projectile).
    63.    
    64.         myTransform.Translate(Vector3.up * projectileSpeed * Time.deltaTime);                    
    65.  
    66.  
    67.        //If the ray hits something then execute this code.
    68.    
    69.         if(Physics.Raycast(myTransform.position.up, out hit, range) &&
    70.           expended == false)
    71.         {
    72.             //If the collider has the tag of floor then..
    73.          
    74.             if(hit.transform.tag == "Floor")
    75.             {
    76.              expended = true;
    77.          
    78.          
    79.              //Make the projectile become invisible.
    80.          
    81.              myTransform.renderer.enabled = false;
    82.          
    83.          
    84.              //Turn off the light. The halo will also disappear.
    85.          
    86.              myTransform.light.enabled = false;
    87.             }
    88.        }
    89.     }
    90.  
    91.  
    92.     IEnumerator DestroyMyselfAfterSomeTime()
    93.     {
    94.         //Wait for the timer to count up to the expireTime
    95.         //and then destroy the projectile.
    96.    
    97.         yield return new WaitForSeconds(expireTime);
    98.    
    99.         Destroy(myTransform.gameObject);
    100.     }
    101. }
     
    Last edited: Oct 27, 2015
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Use forum code tags please :)
     
  8. Srooney193

    Srooney193

    Joined:
    Oct 27, 2015
    Posts:
    4
    Sorry still trying to learn all this as I go along, Is that easier to understand now i edited my last post.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Don't have time but I would suggest revisiting the following bit of code which don't make much sense:

    myTransform.position.up (line 69 in the paste)

    It should probably be myTransform.up - please be careful of autocorrect trying to be too helpful if that's the case..
     
  10. Srooney193

    Srooney193

    Joined:
    Oct 27, 2015
    Posts:
    4
    OK I'll try that thanks
     
  11. Sruthin55

    Sruthin55

    Joined:
    Oct 3, 2015
    Posts:
    3
    Hi I just have a problem with UNET and I've been stuck on for quiet a while now . Here is what I want
    I want the host and the client to be able to instantiate an object

    public void objectPlacement() {
    if (isLocalPlayer) {
    if (Input.GetKeyUp(KeyCode.E))
    {
    Debug.Log("InsideKeyCodeE");
    placedObstaclesCounter++;
    Debug.Log ("placedObstaclesCounter");
    Debug.Log (playersObstacles.Length);
    if (placedObstaclesCounter < playersObstacles.Length)
    {
    Debug.Log("InsidePlace");
    CmdGenerateObstacles ();

    Debug.Log("InsidePlace222");
    }
    else
    {
    Debug.Log("Player1'sobstacleplacementisdone!");
    //lane.transform.position=endPosition.transform.position;
    //this.gameObject.SetActive(false);
    }
    //}

    }

    }
    }

    [Command]
    public void CmdGenerateObstacles ()
    {
    Debug.Log("InNetworkSpawn");
    GameObject prefab = playersObstacles [placedObstaclesCounter];
    spawnPosition = GameObject.Find (thisPlayerName).transform;
    GameObject newObstacle = Instantiate (prefab, spawnPosition.position,Quaternion.identity) as GameObject;
    movingObstacle = newObstacle;
    NetworkServer.Spawn (newObstacle);
    newObstacle.transform.parent = localPlayerPlane.transform;
    }

    The host is successfully able to spawn an object and works fine , but nothing happens when I try to run it on the client . I have localplayerautority set and all the prefabs have network identity and are set as spoonable objects in network manager . Any help would be greatly appreciated
     
  12. rikor420

    rikor420

    Joined:
    Dec 14, 2016
    Posts:
    1
    Hi, i just bought your full package on Steam, and wanted to know if S1 and S2 is 5.0+ capatiable?
     
  13. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    Hey is this where you post comments for your new Series S1 more than a gamers? If so I had a question, in video 5 Network Health Bar you said the code

    transform.LookAt(Camera.main.transform);

    knows what to look at based on the tag "MainCamera" on the FirstPersonCharacter. I don't understand how Camera.main.transform means the tag "MainCamera" ? What happens if you have multiple cameras in a scene for the local player? How does Camera.main.transform know what camera to look at? How do you make the look at function, look at the right gameobject? could you just store this like a variable?

    public GameObject lookAtTarget;
    transform.LookAt(lookAtTarget.transform);

    would this work?
     
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It will only work if there is just one camera tagged as MainCamera of course.
     
  15. Mboko

    Mboko

    Joined:
    Dec 14, 2013
    Posts:
    5
    Hey GTGD,

    Really interested in buying your tutorial series on Steam for networking in Unity, wanted to ask you what is hopefully a quick question to make sure I will find the answer in your series (if not, perhaps I can ask you directly, and I will still of course buy your tutorial):

    I'm looking to make a 2d co-op action game, and the idea of networking variables across a server seems fairly straightforward. What has always puzzled me is exactly what is required for a client/server to client setup. Any documentation I read seems to indicate this is only possible on LAN, online connection would require using Unity's matchmaking service which would result in paying to increase CCU. I want to release the game on Steam and I know I need to get my head around steamworks to connect friends together - is there a way to get this connection going without requiring Unity's matchmaking services, eventually ending up in fees? No dedicated server needed, just want friends to be able to play together without incurring a cost. Is this possible, and is it answered in your tutorial?

    Looking forward to hearing your response to this - if your tutorial will cover this that would be fantastic. If not, point me in the right direction or (and this I'd prefer) we could arrange something so I can learn what I need to know and I will pay you for your time? Really need to get this solved!

    *Edit* - Using playmaker Unet package to make this task a bit simpler, just wanted to let you know if this makes any bit of difference
     
  16. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Hello Mboko,
    • Currently to the best of my knowledge UNET doesn't have a public standalone server arrangement. It is in Unity's development pipeline from my understanding.
    • Yes to have public games you'd need to pay for CCU. I remember seeing an asset on the asset store for UNET that would help reduce usage of Unity's matchmaking service and so save the developer money. I've never used it though, and can't remember what it was called. It also only works for PC games.
    • While I did utilise the achievements feature of Steamworks for my game Guild Commander, my knowledge on steamworks integration it is out of date. I haven't studied into how you could utilise Steam servers to your advantage.
    • If friends all connect to each other on the same virtual private network then they can play a LAN game together without having to use the matchmaking service. This is typically how friends played Minecraft games together without getting onto a public server.
    • In my experience using Playmaker will not save you anytime especially with respect to multiplayer. It's better to learn the scripting because you will ultimately end up scripting for serious projects.
    • Don't buy my tutorial if it isn't going to help your learning objectives. Making games can be expensive and the monetary return can be really quite small. Save the money for when you might eventually have to purchase art or sound assets.
    Sincerely,
    GTGD
     
  17. niknakgames

    niknakgames

    Joined:
    Aug 7, 2015
    Posts:
    25
    Hey had a small issue with re-spawning. Rewrote the code a dozen time with no luck. My character model gets activated on my client (doing a third person), but never on any of the other clients. I tried doing a clientrpc, but it only works on the "Host". Any help would be appreciated.

    Edit:
    I looked at your code again and noticed you have the respawn set in the clientrpc so its getting called on all clients. I was trying to do respawn with a button and I can't seem to wrap my head around why I cant do command or rpc calls. I'm getting various errors. Driving me crazy.
     
    Last edited: Dec 14, 2017