Search Unity

[Updated] 2D Online Shooter Tutorial

Discussion in 'Assets and Asset Store' started by Kurtav, Feb 2, 2017.

  1. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Using this asset you will learn how to create your own 2D online shooter!

    link package: http://u3d.as/ugv



    Screenshot of an example of simulation, network behavior of players:



    An example of a traffic load using multiple player clones whose behaviors are transmitted over the network:

    List of features:

    All of these settings are changeable in a Play Mode (using only one file) :
    - mobile and PC controls;
    - player settings ;
    - other settings(sparks,bonuses,field size);
    - network simulation (clones,atacking,moving,rushing);

    Documentation describes:
    - how to use Photon Cloud to transmit data over the network;
    - how to avoid stack overflow due to the usage of RPC with PhotonTargets.AllBuffered;


    If you have any questions, please do not hesitate to contact me: aleksandronto@gmail.com
     

    Attached Files:

    Last edited: May 25, 2017
  2. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Update 1.1 :
    -- The recharge time (the Settings file - shot cooldown) is now more accurately calculated.
    -- Fix red bag - During immortality, if you switch control from the keyboard to mobile control - a link to the Null.
    -- The joystick did not move by clicking on the top of the screen (Overlapped another UI).
    -- When clicked on the edge of the screen, the joystick would go behind the screen.
    -- The touch area moved together with the joystick.
    -- Fixed saving the Settings file after exiting from the Unity. Now there is a way that always works correctly.
     
    Last edited: May 4, 2017
  3. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    This video shows an example of how to observe the behaviors of players that are transmitted over the network.
    Thanks to this simulation, you do not need to ask someone to download the assembly so that he came to your room and played with you.

    I also highly recommend testing this simulation with different speeds, with different respawn rate of bullets and different number of players. Due to this, you will approximately understand when a queue of transmitted data on the network occurs and when a packet transmission delay occurs. This is important to understand because in PUN(PhotonCloud) the limits come very early.

    Has altered the script which shows the data of the transmitted traffic in the room. PhotonStatsGuiPerSecond.cs .
    I advise you to enable it to understand more accurately - how many it is necessary to transfer a byte of traffic, so that after that queues and delays in the transmission of packets arise.

     
  4. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Update 1.2

    Update File Settings :
    Add rush simulation
    Add rush_all,atack_all,move_all

    Fixes :
    - Fixed bug - While pressing Fire1 in FixedUpdate() sometimes returns a Input.GetButtonDown("Fire1") == false
    - Did not display the game icons in the installed android build on the mobile device
    - Removed function fix() from the script ConnectRoom
    - The variable bullet_speed did not work in the Settings file
    - Fix points spawn bonuses
    - Fixed red bug PUN - "Ev Destroy Failed. Could not find PhotonView with instantiationId "



    For example, thanks to this simulation, we can consider the temporal paradoxes in the network
     
  5. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Update 1.3

    Update File Settings :
    Add amount clones
    Add amount bonuses
    Add field size

    Fixes:
    - Now immortality can be changed in the play mode of the Unity through the file Settings.
    - Nickname of the player in the table will now be displayed correctly.
    - In the immortal, the simulation of the attack did not work
    - If you turn on rush simulation but turn off the simulation of the movement then the simulation of the rush did not work


    By cloning players, we save CPU load. We open fewer ps builds, but we transfer more network traffic.
    It's also worth noting that opening four PC builds without clones and opening two PC builds with one clone is not the same amount of transmitted traffic. Although the number of objects transmitted over the network is the same(4==4). The fact is that updates(OnPhotonSerializeView) of photonoViews of one player are combined (all of its objects(PhotonNetwork.Instantiate)).
     
  6. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Hello, just purchased your asset and I'm very excited.
    I'd like to load a new scene with scene manager when my player is destroyed.
    In which script/position should i add this?
     
  7. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    2DOnlineShooter - Scripts - Multiplayer - PlayerBehavior
    This function(destroy_player) is called to all players.

    upload_2017-6-2_5-37-14.png

    In the blue square, the one who dies. (The owner of the prefab player) In this condition, load the scene.
    In the red square, the one who killed this player (the one who sent this RPC destroy_player to everyone)
    As for the top lines(174-177), then all players must fulfill them because all players must see the transition of the player's state to a state of death.
     
  8. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Hello and thanks for your reply:
    I get this error: when player is killed:

    Ev Destroy Failed. Could not find PhotonView with instantiationId 1011. Sent by actorNr: 1
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2541)
    ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)

    i added this in player beahvior:
    Invoke("Destroy", 1f);// allow time for playing the explosion animation
    SceneManager.LoadScene("start"); // ADDED THIS LINE
     
  9. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    This red error tells you about the conflict in the line PhotonNetwork.Destroy. When you exit the scene, links to deleted objects are lost and PUN does not understand what to delete.

    Yellow warnings of the incomplete sending of the entire stack of calls to the RPC functions can also occur.
    (“Received RPC "name_function_rpc" for viewID but this PhotonView
    does not exist! Was remote PV. Remote called. By: 1 Maybe GO was
    destroyed but RPC not cleaned up.”)

    To completely avoid these errors, you need to write the following -

     

    Attached Files:

  10. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Hello again,
    ist works, when player is killed he is moved to my start screen.
    From my start screen i'd like to run the scene "game" again, but the player does not join the room. It stops at "joinedLobby":
     

    Attached Files:

  11. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Script "ConnectRoom" does not load the room.
    To leave the room to load another scene and go back into the room, I prepared a code for you -




    It is necessary to remove one conflict. Edit script "BoxSprite"

     
  12. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Thank you very much!
     
  13. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Thank you for buying my package =)

    P.S : Who buys my packages do not hesitate to ask questions!
    I will be happy to help you quickly navigate the content of the package.And for any questions on the topic of PUN, too, I answer =)
     
  14. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Is there any solution/tutorial to add an AI (bots) to the game for the case that not many player are online?
     
  15. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    https://www.assetstore.unity3d.com/en/#!/content/86022
    In the video package, you can see how I transfer much fewer bytes of traffic over the network using my methods. Thanks to the latest update(1.1), reduction dictionaries reduced the transfer of 200 bots to a transmission size that does not exceed MTU(1200 bytes) . ByteCountLastOperation ~ 1000 - 1100 bytes
    p.s . : In the package documentation it is written that such MTU.
     
    Last edited: Jun 17, 2017
  16. knuppel

    knuppel

    Joined:
    Oct 30, 2016
    Posts:
    97
    Hello, is your asset
    2D Online Full
    mobile ready?
     
  17. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    In the first updates of this package, I will not add mobile management. I will expand the role-based part in it.
    I'm currently working on another project ("Race Online Example"). I'm sorry.

    You bought my 2d online shooter tutorial package, right?
    Copy the control from there. What is the problem?
    -- script CrossPlatformInputManager Initializes management(pc or moblie) Lines 15-35
    The response of pressing the buttons does not get out in the usual way(Input.GetAxis("Horizontal")), but through the class CrossPlatformInputManager.GetAxis("Horizontal")
     
  18. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    165
    hey i need help with a script of mine as when the player respawns multiple versions of player 1 then respawn XD here is the script:


    Code (CSharp):
    1. void OnTriggerEnter2D(Collider2D other)
    2.     {
    3.         if (other.gameObject.tag == "Player")
    4.                 other.gameObject.GetComponent<Animation> ().Play ("Death");
    5.  
    6.                 Invoke ("Destroy", 3f);
    7.     }
    8.  
    9.     void Destroy()
    10.     {
    11.         FindObjectOfType<ConnectRoom>().OnJoinedRoom();
    12.         PhotonNetwork.Destroy(gameObject);
    13.     }
    i put this on my death trap game object.
     
  19. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    In the OnTriggerEnter2D function, you hit more than once.
    You need to get into the OnTriggerEnter2D function once

    Code (CSharp):
    1.  
    2.     bool flag;
    3.     void OnTriggerEnter2D(Collider2D other)
    4.     {
    5.         if (flag)return;
    6.         flag = true;
    7.         if (other.gameObject.tag == "Player")
    8.                 other.gameObject.GetComponent<Animation> ().Play ("Death");
    9.  
    10.                 Invoke ("Destroy", 3f);
    11.     }
    12.  
    13.     void Destroy()
    14.     {
    15.         FindObjectOfType<ConnectRoom>().OnJoinedRoom();
    16.         PhotonNetwork.Destroy(gameObject);
    17.     }
    Once the trap has been activated, it is necessary again flag = false;
    So that after the spawn you can again fall into the trap
     
    Last edited: Aug 21, 2017
  20. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    165
    only problem is now the player can't rush and there is still a copy of player 1 (or any player for that matter) running around
     
  21. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    the problem was solved. The problem was that the trap was removed instead of the player
     
  22. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    165
    yep i thank you for your timeand the help :D