Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Tanks Multiplayer - complete networking project [UNET]

Discussion in 'Assets and Asset Store' started by Baroni, Jun 11, 2016.

?

Which networking solution would you like to use with this asset?

  1. Unity Networking

    99 vote(s)
    60.0%
  2. Photon Networking

    57 vote(s)
    34.5%
  3. Other

    9 vote(s)
    5.5%
  1. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Thank you! I fixed it. In the PlayerExtensions script, there were a bunch of if(PhotonNetwork.OfflineMode == true) statements, and when I got rid of those, it works!
     
  2. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Hi, I have another issue. When I spawn the turret,(in online mode) the turret looks good to the localPlayer. But when a second player joins, the turret doesn't work anymore. By that, I mean the second player can't hit it but it can hit it and a lot more confusing stuff.

    My turret has the PlayerBot script. It is essentially the same as the bottankfree, but can't move.
    Please help.
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Unfortunately I am unable to help with your own code, since obviously I do not know what you are doing (do not post source code in this public forum). I would suggest checking how in the offline mode, the GameManager spawns PlayerBot objects and then verifying the workflow for online mode too. Also re-check the colliders and team assignment.

    Non-player objects / NPCs / online bots are on my to do list and something that I am working on for a future update, but I cannot provide detailed support for it right now (and your own implementation).
     
  4. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Could I email my code to you?
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Yes, however I am not going to provide fully working code as a result - only pseudo code or hints. I hope you understand that this asset was meant as a tutorial after all, so teaching 1-1 is not going to happen.
     
  6. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Last edited: Nov 18, 2018
  7. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Hi, I'm just curious how I can add a new PlayerExtensions method. Like if I could add a SetFireRate or something. How would I do this?
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hi @Claudiotheworm,

    the PlayerExtensions class is a separate script where you can add your own offline+online methods for writing values to player's custom properties. You can search for SetHealth and its "health" property as an example, to get an understanding on how it is done.

    Since this is the part that writes values to player custom properties, you also need the part that accesses them and sets it on the actual player object. Have a look at the references which are accessing SetHealth and GetHealth before implementing your own.
     
  9. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Where is the part that acceses them and sets it on the player?
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
     
  11. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Where are these references?
    Edit: do you mean when you use it like: this.GetView().SetHeatlth()?
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
  13. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Hello! I'm currently trying to make my game into last man standing. I need a way to make all players in game NOT be able to hurt each other until, let's say, three players are in game. Then the server is made unavailable to other people who wish to join. And the round starts and people can start damaging each other. Then it begins as last man standing. How could I achieve this?
    Edit: also, if you die, I need a way to kick you from the game somehow shortly afterwards.
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hello @Claudiotheworm,

    I would mainly use existing methods sent from the server > clients for this as your workflow should be a sequence of events happening.

    The server (master client) is responsible for hit detection. The TakeDamage method in Player.cs is only server-sided, so you would just not let it execute during this phase. I guess you would introduce a boolean variable "gameStarted" and check PhotonNetwork.playerList for the count of players at the very top of it.

    You would do this in the OnPhotonPlayerConnected call as described here.

    PhotonNetwork.room.visible = false;
    PhotonNetwork.room.open = false;

    The CmdRespawn method in Player.cs is called when the player wants to respawn again (read its description). You could change this to let it disconnect from the server instead, and increase the respawn timer in the GameManager inspector. This way, instead of respawning, players would disconnect after the respawn time is over.
     
  15. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Thanks for your help! I will try this soon. It sounds simple enough. Thanks!
     
  16. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Hi, just a minor thing. But, let's say I DONT want to kick people after death, how do I detect only one tank left in the game? There are still other people in game but they will be spectators, so I doubt I can use photonnetwork.list. And once I detect only ONE player left, I need to be able to activate the "win" function on the gamemanager.
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    You can. Check PhotonNetwork.playerList[ i ].GetHealth() on each player to find out how many players are still alive.
     
  18. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    How would I say PhotonNetwork.playerList[ i ].GetHealth() and where would I put it to activate the "win" function(where is the place the "win" function is activated anyway?)?
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    You could do the check whenever a player dies, in the Player.cs TakeDamage method. If you take a look at it, this is also where the GameOver workflow is started.
     
  20. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    Ok... Thank you!!
     
  21. Claudiotheworm

    Claudiotheworm

    Joined:
    Jul 27, 2018
    Posts:
    24
    But, how would you SAY the check? I'm doing if(PhotonNetwork.playerList.length == 1) currently. How would I say PhotonNetwork.playerList[ i ].GetHealth()? Would I do If(PhotonNetwork.playerList[1].GetHealth() >= 1)? I didn't really understand it.
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    You need a loop.
     
  23. rubble1

    rubble1

    Joined:
    Apr 25, 2010
    Posts:
    78
    Hi I'm considering this asset for use with an existing controller I have. It already does work with Photon PUN classic. Could you just give me an idea of how difficult/what would be involved in integrating an outside controller into this framework?
    Can you have less than 4 teams?
    Also, are there any other game modes (say a capture the flag, for example)?
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Thanks for your interest @rubble1. If by "controller" you mean an actual input device, then Tanks Multiplayer supports both desktop and mobile input where the movement direction is just a value of 0-1 on the x/y axis, which you could map your controller to. Instead if you mean a different player object, you'll have to do some setup (colliders, layers) but they are also just game objects after all. The documentation included describes all concepts used by the player objects, which are pretty much indepedant from the network implementation.
    Yes.
    Currently team deathmatch is the only mode available, besides offline mode.
     
  25. gas777

    gas777

    Joined:
    Jun 25, 2014
    Posts:
    10
    Hi, does Tanks Multiplayer work with photon2?
     
    rubble1 likes this.
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hi @gas777, we didn't rewrite Tanks Multiplayer for PUN2 yet. I will do so over the course of this year, when PUN2 is technically mature for production.
     
  27. gas777

    gas777

    Joined:
    Jun 25, 2014
    Posts:
    10
    I see, thanks a lot.
     
  28. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    47
    Hi your game looks great and i want to buy.

    But

    i want to ask a couple of questions.

    Can i replace tanks with car or other vehicle?

    can i replace bullet prefab with mine?

    thanks in advance.

    King Regards.
     
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hello @egem2015. As with all Unity projects, the models used in our asset are sample models only for reference. Of course you can use your own models.
     
  30. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    47
    So i mean your player controller script supports cars and wheel rotation and all car features?
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    It does not. The asset is designed as a networking template, not a car simulator :) You will have to build your own ideas on top of the base systems.
     
  32. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    182
    Will you be upgrading the project to support the new Unity 2019 networking(not sure what name they are using)?
    If not will you be creating a new asset that uses the new networking?
     
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Yes, as soon as there are some more high-level components from Unity to work with. Plans can change, but I would like to make a (free) update instead of a new asset.
     
    Warsoul likes this.
  34. Warsoul

    Warsoul

    Joined:
    Sep 9, 2016
    Posts:
    35
    Great news ! Let me know ehen it's updated ! This asset will be awesome if we can fix the multiplayer lag issue at fast speed.
     
  35. medouerghi88

    medouerghi88

    Joined:
    Sep 7, 2018
    Posts:
    1
    Thanks ,this is the best asset.please I want to add score for each player from the winning team after the end of each match.can you help me
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hi @medouerghi88, could you please join our dedicated support forum? Your question needs more than once sentence to answer :) Please also name which networking provider (UNET or Photon) you are using there.
     
  37. unity_oiO8GWzlr-ri-Q

    unity_oiO8GWzlr-ri-Q

    Joined:
    Oct 25, 2018
    Posts:
    4
    Hi all,

    I'd like to try downloading your demo to turn it into another game. Before buying the package, some questions:
    1) Does offline networking vs AI need a server? In this case does it have limits on the maximum number of users or is it in the local area infinite?
    2) using the unity server what limits are there? Are there prices based on usage?
    3) I would like to replace both tanks and projectiles with other assets, is it a complex operation?

    Thank you
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Hi @unity_oiO8GWzlr-ri-Q,
    It depends on the networking provider you would like to use. Photon does not need a server in offline mode, which then runs local only. Unity Networking does not have an explicit offline mode - we create a LAN game with a maximum player count of 1 instead. Both ways are basically only limited by performance on your device.
    The limit is your wallet :) You can find a cost calculator on the official page.
    Tanks and projectiles are prefabs which consist of models + scripts. If you're familiar with how Unity works, this won't be a problem.
     
  39. unity_oiO8GWzlr-ri-Q

    unity_oiO8GWzlr-ri-Q

    Joined:
    Oct 25, 2018
    Posts:
    4
    Oh thanks for the quick response.
    I thought you received an email with every answer, sorry if I answer only now!
    Ok so if the game is only offline I could use photon to create a local 1 player server and the rest of the players are AI.

    is it prepared to do this scenario?

    thanks again
     
  40. unity_oiO8GWzlr-ri-Q

    unity_oiO8GWzlr-ri-Q

    Joined:
    Oct 25, 2018
    Posts:
    4
    Oh, I read about a negative review because after a recent update the project contains numerous errors.
    Two questions:
    1) Can I receive a message of how stable the code will be? I would like to try it without incident :)
    2) In the link you wrote it says "Unity Multiplayer (UNET) is being deprecated." ... so it's better use photon?

    Thanks!
     
    Last edited: Apr 28, 2019
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    As I said, Photon has a dedicated "offline" mode that doesn't need servers:
    https://doc.photonengine.com/en-us/pun/current/gameplay/offlinemode

    Please stick to english for your questions.
     
  42. unity_oiO8GWzlr-ri-Q

    unity_oiO8GWzlr-ri-Q

    Joined:
    Oct 25, 2018
    Posts:
    4
    Sorry! Now it’s translated
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Sure! The asset currently works up to Unity 2018.4 without issues. I am working on an update dedicated for Unity 2019.1 which will be available very, very soon - it is a big update that will add even more exciting features.
    Unity works on a new multiplayer service running on Google Cloud. Since that isn't anywhere near finished yet, I would recommend going with Photon if you're just starting out.
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Version 1.4 is now live.
    THIS VERSION IS NOT BACKWARDS COMPATIBLE

    Major features were added: new game mode - Capture The Flag!
    Also, we bumped up the minimum required Unity version to fully support Unity 2019.1 (for both UNET or Photon packages), integrated the Lightweight Render Pipeline and updated Photon PUN 1 to PUN 2 along the way.

    TanksMultiplayer_03.png

    Full changelog below.
    • added optional area damage (maxTargets, explosionRange) to Bullet
    • added friendly fire checkbox option to the GameManager
    • added GameMode dropdown to matchmaking selection
    • added logic to load random map for specific game mode
    • added logic to grant points in consideration of game mode & score type
    • added Capture The Flag game mode (+new map: CTF_Game)
    • renamed Powerups to Collectibles to better describe their versatility
    • Collectibles can now be consumed or picked up, dropped and returned to their origin
    • added CollectibleTeam (for flags in CTF) and CollectibleZone class for team bases
    • Collectibles make use of a new network sync method: buffered RPCs (see documentation)
    • PUN: updated from PUN 1 (Classic) to PUN 2 (v2.9)
    • added Lightweight Render Pipeline (LWRP) dependency
    • minimum Unity version: 2019.1.0
     
  45. WardeG

    WardeG

    Joined:
    Mar 25, 2013
    Posts:
    8
    upload_2019-5-2_13-13-31.png after importing the package, such errors appear. How to fix it ?
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    Please read the documentation pdf included in the package. You probably did not import the UNET package via the Package Manager.

    Also please register on our support forum in case of further issues.
     
  47. WardeG

    WardeG

    Joined:
    Mar 25, 2013
    Posts:
    8
    immediately after importing yunet, these errors appear.
    I do everything according to the instructions
    Unity latest version
    5 times in a row tried but the effect is the same
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    @WardeG We're not providing support here. Please head over to our forum so I am able to share more instructions.
     
  49. WardeG

    WardeG

    Joined:
    Mar 25, 2013
    Posts:
    8
    Invoice ID plz
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,285
    You obviously have to enter your own invoice ID from your Asset Store purchase email.