Search Unity

Third Party New Photon Unity Networking Tutorial Series

Discussion in 'Multiplayer' started by Oliver-Eberlei, Apr 17, 2014.

  1. Sasstraliss

    Sasstraliss

    Joined:
    Feb 24, 2013
    Posts:
    10
    PhotonNetwork.time for the projectiles doesn't update every Update() for me, it only updates every 5 or so calls to Update(), resulting in very jagged movement. What can I do about this?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    PhotonNetwork.time uses a simpler but less accurate way to access the system's time (Environment.TickCount). This updates only every 15ms or so. Could this really cause the issues? It would still give you approximately enough precision for 60 frames/sec.
    You could attempt to swap the networkingPeer.LocalMsTimestampDelegate for a method you provide. That could wrap a Stopwatch (e.g.), which is more accurate. You can't wrap Time.time, because that only works on the main thread.

    Try this. Modify the end of the NetworkingPeer constructor to setup a stopwatch and add the method below:

    Code (CSharp):
    1.  
    2.         sw.Reset();
    3.         sw.Start();
    4.         this.LocalMsTimestampDelegate = this.AccurateTime;
    5.         this.State = global::PeerState.PeerCreated;
    6.     }
    7.  
    8.     Stopwatch sw = new Stopwatch();
    9.  
    10.     private int AccurateTime()
    11.     {
    12.         return (int)sw.ElapsedMilliseconds;
    13.     }
     
  3. m4ng4

    m4ng4

    Joined:
    Apr 17, 2013
    Posts:
    9
    Hi all! Trying my best to implement this into my game but really having a hard time.. also a 7 month old problem that the game dosent sync time over clients... i think HugoPeters commented on that Nov 13, 2014 tried it and ofc it dident work and seams to work if i try "if not masterclient" instead.. and sorry to say this but i dont like to buy something that dosent work as it should when im trying to learn.
    Also has this thread died?
    Oh and the videos are greate but i think the scripts help alot more...
    I'm so sorry to say all this.. but am i missing something
     
    Andreas12345 likes this.
  4. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    I agree with m4ng4. Some things have to be fixed.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    We updated the package with PUN v1.60 and a fixed level loading (using PhotonNetwork.LoadLevel() on the Master Client). It is compatible with Unity 5.1 (ignoring non-breaking compiler warnings about obsolete syntax).

    There are two known issues open still: Projectiles movement might be jagged on some devices and the round time does not sync for joining player.

    We hope the tutorial is useful for you despite some rough edges.
    Please watch the videos and based on those, decide if you want to get the project. You get some assets and all the scripts from the videos. All money made from purchases goes completely to Olli (who is super busy but says "hi").
     
  6. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    Hi,

    Thank for your tutorial, I on a problem with collision.

    I have made a game where you can fire spell (one every 3 secondes for example).

    I check on client side if the spell touch, the issue is:

    There is 2 players, A and B

    Imagine player_A lag, so the player_B become immobile, the player_A shoot him easily. Then the RPC from A is send to B, to said your are dead, but the player B wasn't at the good position.

    I have no idea how to do that correctly.

    Wrong decision for me
    Solution 1 : Ask player B, are you near that position ? if not, I make no damage, but that make a bad user experience for player A

    Solution 2 : Check last value receive from user B, if that is "too old" ... bad user experience too

    The only good solution is to make my own server logic with server photon and validate position of each player on server etc... (Game logic). But my skill level for server is near 0. I hope I will found other solution for my game.
     
  7. XCO

    XCO

    Joined:
    Nov 17, 2012
    Posts:
    380
    I Oliver TY so much for all of this that you have created! I was wondering is there any chance you might make a Tutorial showing PHOTON with PLAYMAKER ? :D
     
  8. minthiha

    minthiha

    Joined:
    Dec 4, 2013
    Posts:
    9
    Thanks You so much bro. That's what tutorial I've find.
     
  9. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Did anybody have fixed the synch time problem?
    What about to share some stuff here? Add a weapon, add sounds, Add new Maps

    I can start with some:

    in ShipMovement.cs:
    Code (CSharp):
    1. newPosition.y = Mathf.Clamp( newPosition.y, 0.5f, 500f ); //50f so you can fly higher ranges
    there are 2 entries ca here: Line 276 and Line 473

    In Prefabs/FX/FX_Explosion you can just add a AudioSource to have sound on explosion.

    Sound to projectileHit in ShipShooting.cs

    Code (CSharp):
    1.     public void SendProjectileHit( int projectileId )
    2.     {
    3.         if( PhotonNetwork.offlineMode == true )
    4.         {
    5.             OnProjectileHit( projectileId );
    6.             this.GetComponent<AudioSource> ().clip = HitLaser;
    7.             this.GetComponent<AudioSource> ().Play ();
    8.         }
    9.         else
    10.         {
    11.             PhotonView.RPC( "OnProjectileHit", PhotonTargets.Others, new object[] { projectileId } );
    12.             this.GetComponent<AudioSource> ().clip = HitLaser;
    13.             this.GetComponent<AudioSource> ().Play ();
    14.  
    15.         }
    16.     }
    I think when anybody share a bit, then anybody can make some progress.

    I think the following parts could be interesting:
    Add new Weapon (Rocket Launcher for example)
    Add new Pickups (Double damage for example)

    I think also ExitGames can earn some money when provide some new Tutorials for this.
     
  10. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Hi. Got the package some months ago. Did have a quick look and all looked really good built and commented.

    I had already a quite simple random match making in my game working super smoothly but need to build a proper lobby.

    The only thing I miss is that with the sync player loading the players are not spawn in specific spawn spots so that they do not overlap. Think of a racing start grid. How could it be managed in the network so that each player spawns in an specific spawn spot?
     
  11. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Greetings,
    Has anyone gotten Sky Arena to work with WebGL export?
    I've gotten another Unity-Photon race game to work with WebGL by moving the 'chatapi folder from plugins to the assets root folder'.
    The error was related to websocketstcp(if I recall) but that issue was resolved by moving the chatapi folder in the race game.
    Due to the more complex chat system in Sky Arena I can understand why there may be an issue.
    I tried both PUN Free and PUN +.
    All replies are appreciated.
    Thanx
     
  12. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    have somone a solution to use ragdoll ?=?
     
  13. keifyb

    keifyb

    Joined:
    Feb 12, 2016
    Posts:
    62
    has this asset been abandoned?
     
  14. diegoadrada

    diegoadrada

    Joined:
    Nov 27, 2014
    Posts:
    59
    Hi Oliver, in SQL Matchmaking, the CreateSqlMatchmakingServer method in Matchmaking script calls the ServerOptions method CreateRoom.
    Then, in CreateRoom method you have this lines:
    Code (CSharp):
    1. MapQueueEntry firstMap = MapQueue.GetSingleEntryInMapQueue( mapQueueString, 0 );
    And:
    Code (CSharp):
    1. roomOptions.customRoomProperties.Add( RoomProperty.Map, firstMap.Name );
    So, this means that if player can't find any room available with his search paramaters, always is going to create a Room with the first map? Because firstMap always is going to read the first value in MapQueue.

    Thanks in advance for your answer.
     
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    This is not the focus of this tutorial, sorry. I am not aware of a solution either but you should be able to trigger "ragdoll mode" when the character is being hit/dies.

    It looks like this, yes. If the property with key RoomProperty.Map gets updated by maps, then matchmaking will always attempt to find the first map.
    This is meant as example usecase. It shows you the properties and methods to use, so you are aware of those and can adjust it to your needs!
    Hope that's OK for you.
     
    JamesArndt likes this.
  16. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
     
  17. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Is there a multiplayer race mode within this project? Also what is the current state of the support on this asset.
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    There is no race mode in the project.
    The project is considered "finished" but of course what you learn with it still applies to PUN and you still can simply watch the videos. Based on those, you should be decide if you want the project or if you want to support Oliver for doing the videos.
     
    JamesArndt likes this.
  19. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I am considering purchasing this project on the Asset Store to use as a base for a new air combat game. First question: Does this project work in Unity 5.3? Second question: Does this project work with the latest PUN+ using the Android platform?
     
  20. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Create ragdoll character and when you die, disable your "real" character renderer and instantiate the ragdoll at same position with rpc.
     
    JamesArndt likes this.
  21. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    The package wasn't updated in a while but it should run in Unity 5.3.
    To update this to PUN 1.74 and newer, you will have to adjust some of the code. There are no major changes in PUN but renaming an API is enough to cause a break.
    So: Some assembly work needs to be done but the principle is the same as before.

    You can check out PUN Free. For Unity 5, PUN+ "only" buys you a 100 CCU subscription. The two flavors of PUN (free and plus) are otherwise the same for Unity 5. You can buy PUN+ anytime to turn your subscription into a 100 CCU one (or add 100 CCU to any paid subscription).
     
    JamesArndt likes this.
  22. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Works the same way as it would in an offline game. Make a ragdoll with the built-in wizard, create a prefab for this, use an RPC (works like a function/method) to instantiate the ragdoll prefab and remove visibility of your non-ragdoll character. You can even got a tiny step further and add a little force to the ragdoll rigidbodies to kick the character up or back or where you like, (or leave it alone so it drops straight down).
     
  23. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    I'm using it in Unity 5.4 and it works like butter : )
     
    JamesArndt and tobiass like this.
  24. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Cool, between you and tobiass I realize this will definitely work as a base for what I need to do! Thank you Kamil-Says for your input as well, always good to hear about a real world use case.
     
    tobiass likes this.
  25. arymangupta

    arymangupta

    Joined:
    Sep 29, 2015
    Posts:
    2
    @Oliver Eberlei
    In your Part one lesson 2 you have used Quaternion interpolation for syncing rotation.
    But i have used(I making this in 2D i.e only rotation along z axis)
    transform.eularAngles = Vector3.lerp(transform.eularAngles,rotationRecived , 180f*Time.deltaTime);
    I tried changing 180 to 90 but still rotation looks snappy. How can I sync angles?
     
  26. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    you are doing the lerp incorrectly, check how to lerp like a pro
     
    JamesArndt likes this.
  27. eljaydub

    eljaydub

    Joined:
    Jan 26, 2015
    Posts:
    8
    Thanks for these great tutorials guys. I'm trying to swap out the Ship_Player_07 model (Assets/Models/Ships) with my own model, but I'm having trouble locating where the Ship_Player_07 mesh is assigned to the Ship resource on PhotonInstantiate.
    Where and when does this happen and how can I use my own model instead?
    How and where does this mesh get added to the empty VisualParent game object?
     
  28. eljaydub

    eljaydub

    Joined:
    Jan 26, 2015
    Posts:
    8
    D'oh, brainfart. My bad. I was just looking at the prefab under /Resources in the Project view and of course Unity doesn't show the prefab's child GO's there so I obviously I did not see the mesh there (you have to drag the prefab into the Scene Hierarchy to see the GO with the mesh renderer and then you can modify the prefab and hit 'Apply' in the Inspector).
    Please disregard my previous post - but I'll leave it up so others might benefit from it.
     
  29. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi,
    I just bought this, however, I am greeted with an error immediately. From the MainMenu, on Connect....


    I bought this, hoping it would smooth out some hiccups I am having in setting up my first multiplayer game, using PUN. Kinda bummed since I dont see many or any PunBehaviors, in the source code. ??
     
  30. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    @renman3000: The error will be due to a client config problem. You need to setup AppIds for Chat and PUN (Realtime). Otherwise the server (rightfully) turns you away with that error.
    You can look up our cryptic codes in the ErrorCode enum. This is "InvalidAuthentication" (I think there should be a better log message for this specific case but maybe it's missing) in Chat.

    Have a look at the readme, the tutorial video series and the scenes. There should be pointers, where to setup the AppIds. Sorry, I don't know the project in and out, to my answer is vague...
     
  31. toivo3d

    toivo3d

    Joined:
    Jul 30, 2014
    Posts:
    4
    Hello. Many thanks to your product, but unfortunately I have a few stupid questions. I have downloaded asset to make a test build with no changes, and in unity all works, but in the build (windows platform), there is no collision on terrain and flag, object, etc. but I can destroy enemy ship (multiplayer is working) Please tell me that it is ok) logs in attachment. thanks
    ____________
    Oh Its not Ok, this problem doesn't exist in unity version 4.7. First I tested in 5.5
    ____________
    So in 5.3 it works too. it suits me, thanks
     

    Attached Files:

    Last edited: Dec 4, 2016
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    @toivo3d: Thanks for the updates. Good (or bad) to know it's not working in 5.5.
    Oliver is not updating the tutorial anymore (doesn't have the time), so we will have to make do.
    We will add a warning in the asset description.
     
  33. RF008

    RF008

    Joined:
    Oct 28, 2016
    Posts:
    20
    Hi does it have matchmaking based on rank system.
    and also how does smooth lerp was working ?
    i am using smooth lerp but i have some jerky movement.
    does the asset have smooth lerp movement?
     
  34. hermolenda

    hermolenda

    Joined:
    Apr 9, 2017
    Posts:
    11
    Is package working with new versions of unity?
     
  35. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Tested with 5.6.0f3 - PC build worked BUT had to delete Photon stuff and reimported newest PUN+.....Pun free should work.Never did get WebGL to work tho.
    .
     
    tobiass likes this.
  36. vet-cat

    vet-cat

    Joined:
    May 29, 2013
    Posts:
    37
    This works for webgl, but the synchronization of the situation leaves much to be desired - perhaps this is due to extrapolation (webgl does not support the udp)



    http://3d-techno.com/SkyArena/BuildWebGL/index.html
     
  37. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Thanx for replying.Did this work 'outa the box' or did you have to make some changes?
    Thanx again!
    EDIT:
    Got it working- I see what you mean with synch.
     
    Last edited: Jul 24, 2017
  38. squall-leonhart

    squall-leonhart

    Joined:
    May 5, 2017
    Posts:
    26
    Hi,

    I am learning PUN and bought your Sky Arena few days ago. I am studyiing your codes and have questions

    Question #1 - I can't seems to figure out how MultiplayerConnector gets the callbacks from PUN when it does not inherit from PunBehaviour or implements IPunCallbacks ? It appears so "magical". After much thought I come to the assumption that on every callback event of PUN, internally there's sort of BroadcastMessage mechanism to call the same name method on all MonoBehaviour in a scene. Is my assumption correct ? If my assumption is correct, why MultiplayerConnector does not inherits from PunBehavior, what's the advantages ?

    Question #2 - I get "Authentication request error : 32767. Disconnecting" and a another related error "SetOnline status called while not connected to front end server" which is caused by ChatHandler. I have created an appId for PUN and another appid for Photon Chat in my Photon account and input the respective appIds into PhotonServerSettings accordingly. Anything else I need to do ?
     
    Last edited: Aug 18, 2017
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    A1: Ultimately, I don't know why Oliver chose to implement the interface and not to inherit from PunBehaviour. Both is possible and more or less a matter of personal preference. And yes, PUN internally either directly calls the method, if the interface is implemented or calls a SendMessage by Unity (slower).

    A2: The error code is for "Authentication failed. Possible cause: AppId is unknown to Photon (in cloud service)." You might want to make sure your AppId is copied correctly to the PhotonServerSettings and that you use ConnectUsingSettings(). There are other ways but this is the most convenient.
     
  40. squall-leonhart

    squall-leonhart

    Joined:
    May 5, 2017
    Posts:
    26
    Hi,

    Thanks for confirming the SendMessage mechanism in Photon. With your confirmation it is no longer that magical ;). On why Oliver used MonoBehaviour instead of implementing IPunCallbacks or inheriting from PunBehaviour, I think he is using the same code base to cater for offline mode as well.

    On the chat authentication error, there's a small bug in Oliver code where the ChatAppId is unasssigned (empty) when the Connect method is called. Below are the modifications

    Code (csharp):
    1.  
    2. // ChatHandler.cs line 188
    3.  
    4. public void Connect()
    5.     {
    6. // modification begin
    7.         if (PhotonNetwork.PhotonServerSettings == null)
    8.         {
    9.             Debug.LogError("Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: " + PhotonNetwork.serverSettingsAssetFile);
    10.             return;
    11.         }
    12.  
    13.         if (PhotonNetwork.PhotonServerSettings.ChatAppID.Trim() == string.Empty)
    14.         {
    15.             Debug.LogWarning("Chat App Id not set in Photon server settings");
    16.             return;
    17.         }
    18.  
    19.         ChatAppId = PhotonNetwork.PhotonServerSettings.ChatAppID;
    20. // modfication end
    21.  
    22.         m_ChatClient.Connect(ChatAppId, "1.0", new ExitGames.Client.Photon.Chat.AuthenticationValues(ChatUsername));
    23.     }
    24.  
    25.  
    .
    I am still learning and would like to know what's the best way to know which region and room a friend is in ? Something like store in player custom properties and make it available as a criteria when matchmaking, possible ?
     
    Last edited: Sep 4, 2017
    tobiass likes this.
  41. evanidul

    evanidul

    Joined:
    Nov 20, 2014
    Posts:
    6
    Hi,

    Has anyone tried this with Unity 2017?

    thanks..
     
    JamesArndt likes this.
  42. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks for the series
     
  43. dawayoapps

    dawayoapps

    Joined:
    May 24, 2017
    Posts:
    1
    Hi, I imported to the new unity 2017.2 and I have multiple errors, but I can't solve only this one. Can anyone help me?

    Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonConverter.cs(48,9): error CS0433: The imported type `UnityEditor.SceneManagement.EditorSceneManager' is defined multiple times

    EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
    EditorSceneManager.OpenScene(sceneName);
    EditorSceneManager.SaveOpenScenes();
     
  44. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    The whole PhotonConverter is no longer needed, so you might focus on removing it, instead of fixing this.
    I guess the clash is due to us re-implementing the EditorSceneManager API for older Unity versions. It's not available in Unity 4.x and so we added it (using the old methods in the newer EditorSceneManager API). Due to the compile defines, this probably "leaks" into 2017 (which we expected to be UNITY_6).

    Find "EditorSceneManager" and remove it or update the define-checks.
     
  45. DemonKira

    DemonKira

    Joined:
    May 3, 2017
    Posts:
    1
    It is compatible with mobile?
     
  46. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    256
    Hello everyone. I see this thread started 3 years ago. Im new to PUN and seek for the best tutorial to start. Are the videos here updated?
     
  47. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    The principle is still the same, so if you don't mind some minor changes in the API, you can still learn a lot from the videos.
    The project wasn't updated though.
     
  48. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Exit Games folks - How tightly is this system coupled to the physics and control of the spaceship? Would this work with a little elbow grease on my part, with car physics? Just simple car control on the ground.
     
  49. LunarLabs

    LunarLabs

    Joined:
    Dec 21, 2016
    Posts:
    17
    Hi all,

    Just before I end up leaving a bash review, can anyone tell me if this worked for them right out of the box and if so; tell me I'm doing something wrong.

    1. It seems like this comes with an older version of PUN (hashtable issues everywhere on load).
    2. Importing the new version of PUN fixes hashtable issues (great..),

    However there are stop errors on the single player mode

    Code (Boo):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. GamemodeBase.SetRoundStartTime () (at Assets/Scripts/Gamemodes/GamemodeBase.cs:69)
    3. GamemodeDeathmatch.OnSetup () (at Assets/Scripts/Gamemodes/GamemodeDeathmatch.cs:25)
    4. GamemodeManager.InitiateSelectedGamemode () (at Assets/Scripts/Gamemodes/GamemodeManager.cs:99)
    5. GamemodeManager.Awake () (at Assets/Scripts/Gamemodes/GamemodeManager.cs:56)
    and via MainMenu.cs

    Code (Boo):
    1.  
    2. Authentication request error: 32767. Disconnecting.
    3. UnityEngine.Debug:LogError(Object)
    4. ChatHandler:DebugReturn(DebugLevel, String) (at Assets/Scripts/Chat/ChatHandler.cs:567)
    5.  
     
  50. Oliver-Eberlei

    Oliver-Eberlei

    Joined:
    Jun 12, 2011
    Posts:
    110
    Hi astrofox,

    we are currently in the process of updating the code base to make it run out of the box with the newest versions of Photon and Unity. Sorry for the current inconvenience.

    I will check the errors you encountered as soon as I get home to the code base and report back to you how to fix them.
     
    rubble1 and JamesArndt like this.