Search Unity

Multiplayer Networked TANKS! Demo Q&A

Discussion in 'Community Learning & Teaching' started by willgoldstone, Sep 21, 2015.

  1. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi all

    So as some of you will have seen we just released a Tanks! tutorial game in which players competed on a single keyboard couch multiplayer style.


    We couldn't resist using Unity's new Multiplayer Networking features to make this demo a 4 player battle arena! We'd love to get your feedback and bugs to make it better - it's a super basic port right now but it should help you to pick it apart and learn from the code. We'll be adding features, polishing the UI etc but we wanted to get you this as soon as the port was working.

    Download-

    UPDATE v1.2

    After a brief bugfix, this project is BACK! on the Asset store.
    https://www.assetstore.unity3d.com/en/#!/content/46213

    Tanks a lot,

    Will
     
    Last edited: Sep 29, 2015
  2. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    When I try to run this in Unity 5.2 I get errors:

    ArgumentException: Input Axis HorizontalUI is not setup.
    To change the input settings use: Edit -> Project Settings -> Input
    UnityEngine.EventSystems.StandaloneInputModule.ShouldActivateModule () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs:140)
    UnityEngine.EventSystems.EventSystem.Update () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/EventSystem.cs:250)
     
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Will check this out shortly, fantastic "out of the box" thinking @Will Goldstone
     
    GFX47 likes this.
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    GFX47 likes this.
  5. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Yep, same input configuration problem as the local multiplayer version of the projet.

    Important note: don't forget to enable and configure the multiplayer service for your project in Window > Unity Services!

    Also add the "LobbyScene" and "CompleteMainScene" scenes in your build settings and launch the game from LobbyScene ;)
     
  6. Livederic

    Livederic

    Joined:
    Sep 11, 2015
    Posts:
    1
    Hi, Does someone else have an issue with hit and/or health management in the networked version ? BR
     
  7. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Updated, see OP.
     
    Livederic likes this.
  8. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    Well theres 2 issues i have with this. Atleast. First off its that you bind color change to the forward direction. which means the player wont get an instant response and said player can hold that forever and only have it happen once.

    I rebound it to the y key. and all is gucchi. instant response. Oh yeah forgot to mention, changed all the input.GetButtonUp to GetButtonDown. Because you want an instant response^^

    Now your actual pushing isn't working. This is because your asking the shell for the local player which it won't ever have because you spawn it and no1 controls it(as my understanding that is)

    moved the if(isLocalPlayer)

    inside of the for loop and made it. if(targetRigidbody.GetComponent<NetworkIdentity>().isLocalPlayer)

    And 1 last thing. the line Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); Will never ever ever ever return anything. Its length will always be 0. Because m_TankMask is only set on the server.

    so for the last paramater i just did LayerMask.GetMask("Players")
     
  9. Mrinaank

    Mrinaank

    Joined:
    Jul 25, 2015
    Posts:
    14
    Hi, I'm still learning unity by watching tutorials. Amazing Tutorial, btw!!! I wanted to try the networking demo, so I created a new project, downloaded the networking demo, built the completed scenes. It works like a charm but there are some problems. Can anyone teach me how to solve them. I have already put it on the unity multiplayer service.

    1) I cant change the name of the game in the lobby scene. it stays as new game.
    2) After clicking on the 'List Servers' the server name is blank. How do I change that? Why is it blank?
    3) Sometimes one of the players screen doesn't show the game but shows the loading screen up to round three, but the players tank keeps moving on the other screens when the player presses the move or shoot buttons.
    4) At least one player when moving at the maximum speed, starts repeatedly acting like it is hitting a screen edge buffer everywhere. But, the other players can easily pass through those areas. Also, when the same player is moving slowly (by releasing the button every few seconds and pressing it again) the player doesn't feel the same effect it was previously feeling.

    How do I solve this? Any help is appreciated.

    Thank You in advance.
     
  10. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    1 and 2 is just click on the inputfield(the thing where it says new game in grey text) They are both related.

    and 3 and 4 might be unet being crap like it is(sorry, but it is.) Does this happen even when u use the play and host button?
     
  11. Mrinaank

    Mrinaank

    Joined:
    Jul 25, 2015
    Posts:
    14
    Yes. but it happens less frequently.
    Thx anyway
     
  12. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    @Mrinaank 1 & 2 are indeed linked to the fact that the placeholder text doesn't clear when clicking on an input box. I'll modify the color to be even more clear that it's not a value & change it to "Enter a name..." instead.

    3 & 4 are a bit more complex ( and not really unet's fault @scnoobi, as it behaves as expected: syncing stuff as fast as it can; but more my fault ;) & the fact that I tried to keep the sample simple - so no fancy predictions etc...)

    3 is definitively a bug. I encountered it before, but though it was fixed. I'll investigate (thanks for the report!), but if it happen again to you, can you check the log of the clients stuck with the loading screen & tell me if there are any Exceptions (especially null reference exception) somewhere in it?

    4 is probably some network problem. Even with broadband speed simulation locally, the problem is minimal here, but on some real network it could be a high ping problem, I suppose.

    The way the project works is to use MovePosition to move the tank. So what happens is that
    - the tank on the client sends its new position to the server
    - the server smoothly interpolates to that position
    - but in the meantime, the other has sent a new position
    - that position can arrive after the tank has reached the previous one, so it was stopped, waiting for new information, hence the stuttering.

    Using velocity/force instead of MovePosition could be a way to reduce that, as then the tank will continue to move following its current rigidbody velocity until receiving a new velocity, and so won't "stop" on server/other client. But I made the decision of keeping the game as close to the non networked one to show the minimal amount of work needed to port a project to multiplayer in its most basic form. A "real" game would probably do something like that, though, as the optimization part..

    You can also try to play with snap & interpolation on the NetworkTransform of the tank prefab.
    - Snap is the max amount the NetworkTransform will try to interpolate smoothly. If between 2 consecutive received positions the tank has moved more than that value, it will be "snapped" (teleported) to that new position. Increasing that could fix some of the problem.
    - Interpolation is the max delta when interpolating. The highest, the faster the object will move toward it's position. Reducing it could also reduce the problem.

    But mainly remember that in a networking situation, passed a certain ping, there won't be any miracle...
     
  13. Mrinaank

    Mrinaank

    Joined:
    Jul 25, 2015
    Posts:
    14
    Thx!. Yes, for the 3rd problem there are a few null reference exceptions.
     
  14. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    Could you paste there here or PM me those please? Thanks for the help!
     
  15. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    Using version 1.3

    @UnityGuillaume There is a pretty fatal bug with how you make rooms. It basically makes the game useless for any kind of multiplayer.
    The bug: The player counter never reduces itself if a players leaves the room and since at x/x the room won't show. you has a problem:D)
    repro:
    Start 2 programs. Create a server on 1. the other 1 is client
    Join as the client.
    now press back(either on connecting or when you have joined the room. Doesn't matter)
    click list servers as client. You will see it is now 2/4. but in your server program it is still you alone.
    (I don't believe it is possible to connect to the room anymore)
    Join the room again.
    cancel when connecting.
    Click list server. It is now 3/4
    Join the room. cancel it.
    Click list server. It is now not visible.


    Okay. not completly unusuable but quite high. Because you only remove the player after said player has been gone for x seconds(dont know how long that is. I believe its like 30-60 seconds)
    And this even happens if you back out from the room which is completly unacceptable.

    Having it as. if you are not inside the room then we do not count you way of going with this. is way better. because it removes your times. you just got to negate people that are trying to join if the server is already full.
    Or reducing the timeout timer and and making the player count go down when a player leaves the room by choice.

    Also Still impossible to rejoin the game after you have joined it once. I joined the room once. i then left by click back. i then tried to rejoin. i left the game for 1-2 minutes and was still on connecting. and when i cancel'd i saw that it was at 1/4
     
    Last edited: Oct 27, 2015
  16. Mrinaank

    Mrinaank

    Joined:
    Jul 25, 2015
    Posts:
    14
    Sure! Ill post it as soon as i start the game again (just saw your post). I was wondering if i could use PUN instead of UNET. If so can anyone tell me how, as i'm almost totally new to unity and multiplayer networking.
     
  17. AlexSledge

    AlexSledge

    Joined:
    Nov 13, 2013
    Posts:
    17
    I'm seeing an issue where the asset for this continually shows as needing an update in the Asset Store, however no matter how often I update it, it remains at version 1.2. Tried manually deleting it and re-downloading, no effect. The asset appears to work just fine, but I saw someone mention a 1.3 above - what is the current version of this tutorial? Is this just an issue on my end (though it's present on both my Windows workstation and Macbook Pro, so... curious)?
     
  18. jchart7

    jchart7

    Joined:
    Mar 16, 2014
    Posts:
    12
    I thought there were Unity Networking Tutorials?(Video version)?? Did these get taken down for some reason... they had the same Tank game on display.
     
  19. Le_Tai

    Le_Tai

    Joined:
    Jun 20, 2014
    Posts:
    442
    Anyone here encountered problems where tank color aren't synced or the game doesn't stop after there only 1 tank left?
    I modified the project a lot so I'm wasn't sure it my fault or the project's:)
     
  20. Dimilicious

    Dimilicious

    Joined:
    Oct 19, 2015
    Posts:
    14
    Hi. Does this game use Photon Networking services?
     
    Last edited: Nov 8, 2015
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No. It uses Unity's new networking.
     
  22. Dimilicious

    Dimilicious

    Joined:
    Oct 19, 2015
    Posts:
    14
    I would like to learn more about it. Where can i get learning material for the new networking? Thank you.
     
  23. jchart7

    jchart7

    Joined:
    Mar 16, 2014
    Posts:
    12
    There were detailed videos on the Networking Version of "Tanks" 2-3 weeks ago... Now I can't find them...I started another thread looking for them... If anyone knows... please link. Thanks!
     
  24. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There isn't much information apart from on these forums and in the unet docs.
     
  25. jchart7

    jchart7

    Joined:
    Mar 16, 2014
    Posts:
    12


    a old 2014 video, but a lot of the concepts are there.
     
    Dimilicious likes this.
  26. Dimilicious

    Dimilicious

    Joined:
    Oct 19, 2015
    Posts:
    14
    Great! Thank you very much!
     
    jchart7 likes this.
  27. Evil-Otaku

    Evil-Otaku

    Joined:
    Oct 17, 2012
    Posts:
    72


    Here is the talk from this years Unite
     
    jchart7 likes this.
  28. Dimilicious

    Dimilicious

    Joined:
    Oct 19, 2015
    Posts:
    14
    Thanks for the video. Good overview. It would be great though if unity people will create an extra section under Learn tab for networking to put all those videos togeather
     
    jchart7 likes this.
  29. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    Which version of Unity are you using? There was a bug at some point that user wouldn't get disconnect on the matchmaker end, so you had to wait for the user to timeout there before being able to join again. This should have been fixed in latest versions, but I will investigate more.

    No the videos are videos from the Training day from Boston Unite 2015. They are for the single computer, 2-local player version. They are still a great source to learn the overall game architecture, but have no networking in them.

    I will try to gather some tips & trick & info regarding how that project was made into an article for the tutorial area. Also incoming is a simple networking tutorial (probably a 2 player racing game) but no ETA on that yet (we will do as fast as we can, I'm aware that networking need some tutorials and we are working hard on that. But the tutorial team need to learn those system too & know them enough to be able to teach about them! =) ).
     
    jchart7 likes this.
  30. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    I can't connect a webGL player to the editor host.
    I host on the editor, then i try to find a server with no success, any idea what it could be ?
     
  31. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    To use WebGL, your server need to be using WebSocket (as it ise what the web technology use)

    On your LobbyManager, in the "NetworkInfo" sub menu, there is a "Use WebSocket" checkbox that you need to tick.
     
  32. Gamrek

    Gamrek

    Joined:
    Sep 28, 2010
    Posts:
    164
    After I updated to Unity 5.3, I have encountered some issues with the project.

    1. There is no NetworkIdentity Component attached to "CompleteShell" prefab
    2. The default Minimum Players is zero on Lobby Manager which makes any one player can start the game without the rest of the players set as ready to play
    3. The shell position don't sync on both clients
    4. The Arrow UI rotation is wrong
    5. The tanks can rotate along x and z axis and it doesn't have a fixed y value in game
    6. After returning back to Lobby, there are two LobbyManager objects in lobby
    I recorded as much as I can and uploaded to YouTube, please take a look.
     
  33. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    So for some reason, the updated 5.3 package was missing quite a lot of thing...Mea Culpa, should have checked the uploaded package too (can I blame end of year fatigue? =p)

    So thanks for the report, there should be an update version on the asset store and I've double checked it's ok. Tell me if you still have problem! (the double lobby fix I've posted in the Lobby topic is included in that one).
     
  34. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    @UnityGuillaume well theres a pretty big bug. but it has to do with your particle system. using latest stable unity version and latest networked version.

    Rightdust trail and left dust trail will spout lots of errors about invalid AABB a and isFinite(outDistanceForSort)

    can be replicated by creating a new particle system and changing the simulation space to world

    2) If you pull completeTank into the hieracy you will get this error
    modifications.empty()
    UnityEditorInternal.InternalEditorUtility:HierarchyWindowDrag(HierarchyProperty, Boolean, HierarchyDropMode)
    UnityEditor.DockArea:OnGUI()
     
  35. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Will there ever be documentation on how this port was made? On the Asset Store the description for this asset still says that it's coming soon.
     
    RedPepper likes this.
  36. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I've started looking at this project now. The first thing I did was to diff it with the local version and it almost looks like a completely different project to me, everything is changed. And it almost feels like it's made with a different engine because of how differently it is structured compared to any other Unity project I've worked with. Like for example, the main game loop is in a coroutine... :p

    I'm trying to figure out how I can add two tanks immediately if I'm playing the main scene in the editor so I can rapidly playtest it while I'm working with it, but the GameManager script gets disabled when I play and I can't even figure that out.
     
  37. DominikP

    DominikP

    Joined:
    Apr 28, 2015
    Posts:
    4
    Hello,
    I have a small problem. When we start game with four players and then one of them leave the game, after a few seconds our room become visible in the servers list. Is it possible to change this default behaviour and prevent player before try to joining to the inaccessible room? This problem makes impossible to create good quality game because player will spend more time for searching accessible room in the lobby than playing in the game.
     
  38. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    most likely its because its got a network identity. It will become active once a room has been created(i believe) which could be done with the hud but don't think adding a second player would work this way:p
     
  39. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Thanks, I'll check that out. I guess I need to start with something simpler as my first UNET project. I was sort of thinking this would be it, but this project seems really complex to me. Especially the lobby-bit.
     
  40. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
  41. Guhanesh

    Guhanesh

    Joined:
    Aug 3, 2013
    Posts:
    7
    Hi, I want to know why the [ClientCallback] attibute was used in Update function in TankShooting.cs
     
  42. Deleted User

    Deleted User

    Guest

    @willgoldstone Hi Will, looks like changes in the 5.4 beta UnityEngine.Networking.Match class prevent this asset from working. Any chance modified versions of the LobbyManager, LobbyServerEntry, and LobbyServerList classes could be posted? Thanks for considering...
     
  43. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    Hi, i have problem with websockets, when i enable it and make build for webgl then put it on my page and run it on 2 web browsers (firefox or chrome either on one or 2 computers) i cant connect to each other (on same lan or wifi). So webgl to webgl connection doesnot see each other.Only how i can make it work is run one instance in editor or in windows build plus second instance as webgl in browser then i can connect to each other and play. But realy when i want to use only webgl builds they doesnot see each other so i cant play this game in 2 browsers (on different computers on same lan or wifi). Do you have any advice how to fix it? Thank you
     
  44. JAB_JAB_JAB

    JAB_JAB_JAB

    Joined:
    Sep 10, 2016
    Posts:
    1
    Hey, is there any way for me to find out which internet port the game is using? And, is there a way that I can change it?
     
  45. Ankaman

    Ankaman

    Joined:
    Feb 14, 2014
    Posts:
    37
    hi
    i have some problems... two days ago i build the game and everything worked fine... today only one client spawns correctly and moves. on the other client no tanks spawned?
     
  46. msabharwal

    msabharwal

    Joined:
    Apr 5, 2017
    Posts:
    4
    Multiplayer Spawning the Client on the fixed locations, i.e. override Round robin as well as Random !!

    Hello, Am not very good at C# and am stuck on the multiplayer. Have a player and Two Spawn points created, everything works fine till the Local Host plays and the Client joins the first time. But if I keep the Localhost connected and disconnect the Client and reconnect client, it spawns over the Local player. The method is set to Round Robin and I need to ensure that the new player / client joining should know if there are positions available and then the player should be placed at the empty Spawn point and not on the existing Local player. Your kind help would be highly appreciated.

    Thanks and Brgds
     
  47. mauri_galvez

    mauri_galvez

    Joined:
    Dec 9, 2016
    Posts:
    4
    I'm currently following the project to implement my own multiplayer game. So far everything has been useful, however I'm experiencing a weird problem at the moment. Whenever I try to join a game from a build I keep getting this exception:

    NullReferenceException: Object reference not set to an instance of an object
    at Logic.Networking.NetworkPlayerManager.Initialize (Logic.Networking.NetworkPlayer player) [0x00000] in <filename unknown>:0
    at Logic.Networking.NetworkPlayerManager.Initialize () [0x00000] in <filename unknown>:0
    at Logic.Networking.NetworkPlayerManager.OnPlayerIdChanged (Int32 playerId) [0x00000] in <filename unknown>:0
    at Logic.Networking.NetworkPlayerManager.OnDeserialize (UnityEngine.Networking.NetworkReader reader, Boolean initialState) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkIdentity.OnUpdateVars (UnityEngine.Networking.NetworkReader reader, Boolean initialState) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.ClientScene.OnUpdateVarsMessage (UnityEngine.Networking.NetworkMessage netMsg) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkClient.Update () [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkClient.UpdateClients () [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00000] in <filename unknown>:0

    It only happens when I try to join a game from a build, I can create a game in build and join game from editor. Anyone has any suggestions?
     
  48. Oscar-Parfitt

    Oscar-Parfitt

    Joined:
    Jun 6, 2017
    Posts:
    1
    I have a question about the tank game, is it possible to make it switch to another scene (different level) once the rounds have been reached.

    Any suggestions, would be greatly appreciated
     
  49. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    39


    Did you know how to fix this issue ?
     
  50. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    Writing this without knowing the code structure but I think the problem is, server instantiates and spawnes the bullets, and sets their first speed by also calculating the tank's speed, but doesn't let the clients know about this. So you have remove the code that sets the speed, and put it in a ClientRpc method and call this method from the Command method.

    This applies if the buggy behaviour is on the client and not on the server, you can check by testing this.

    I hope it helps, if not, you can share the code that generates the bullet and we can help more by investigating it.