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

Third Party Photon Bootcamp Multiplayer Demo

Discussion in 'Multiplayer' started by tobiass, Apr 13, 2012.

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Happy new year :)


    incenseman:
    Thanks for sharing that. I guess it's more than welcome around here :)

    marnes:
    Sorry. This moved over to:
    http://doc.exitgames.com/photon-cloud/BCDemo_Objective/#cat-PLAIN Tutorials

    EagertoLearn:
    Did you find it? I'm not into the code at the moment but usePhoton.cs and PlayerRemote.cs have several places where "spawn" is used in code. Look it up and try get into it to modify and use it for your game.

    Imillionaire:
    You can't create persistent rooms on the Photon Cloud but you could use the Photon Server SDK and C# to make it work any way you like. Depending on your programming skills, it could be a steep learning curve but it's an extremely flexible and powerful foundation.
    The SDK is free to download and the solutions included as source are compatible with the clients that use our cloud so far.
     
  2. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Thank you Tobiass

    so this is the code that handles where the player is spawned after death?

    /// From file: PlayerRemote.cs

    internal void SetSpawnPosition(Hashtable evData)
    {
    transform.eulerAngles = new Vector3(90, transform.rotation.y, 0);
    _DeadSplash = (GameObject)Instantiate(DeadSpalsh, transform.position + new Vector3(0, 1f, 0), transform.rotation);
    Destroy(_DeadSplash, 8);

    Vector3 p = GetPosition((float[])evData[Constants.STATUS_PLAYER_POS]);
    Quaternion r = GetRotation((float[])evData[Constants.STATUS_PLAYER_ROT]);
    this.pos = p;
    this.transform.position = p;
    this.rot = r;
    this.realPos = p;
    this.lastUpdateTime = UnityEngine.Time.time;

    targetpos = GetPosition((float[])evData[Constants.STATUS_TARGET_POS]);
    SendMessage("SetTargetPos", targetpos);

    transform.position = pos;
    transform.localRotation = rot;
    Dead = false;
    }
     
    Last edited: Jan 5, 2013
  3. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    Also find the SoldierDamageControl component of the EnemiesRef.
    It has all the spawn points . These are picked randomly and sent to usephoton code.

    Soldier_Locomotion
    - Soldier
    - Pelvis
    -Spine1
    -Spine2
    -Spine3
    -EnemiesRef


    Max
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    EagertoLearn: What you copied is the code that's called on the other clients when you respawned.
    To find the place where the respawn point is selected, do this:

    Look up where SetSpawnPosition() is called from. Your IDE should do that for you (right click, find references).
    You'll find a switch case with "Constants.EV_FRAG". This is the event that a client sends when it's spawning somewhere. This demo defined these events.
    We can search where it's sent and find: void Dead(Vector3 spawnPosition). For Visual Studio, it looks like this is never called. This could only mean the code calling it is JS or a SendMessage call. SendMessage calls methods by name and that means we might find "Dead" somewhere.
    Searching for "Dead" in any code (JS and CS) finds something interesting in SoldierDamageControl.js. The function Update() calls SendMessage like so:

    _DeadUsePhoton.SendMessage("Dead", Respawn[Random.Range(0, 13)]);

    This in turn looks like a random spawnpoint is picked from the Vector3[] Respawn. As it's not setup in the SoldierDamageControl, most likely this is edited by Unity's Inspector in the Editor.
    Here, I'd throw in a quick fix. Replace the "13" in Random.Range with Respawn.length. Respawn[Random.Range(0, Respawn.length)] will pick one of the available spawnpoints, no matter how many you defined via the Inspector.

    Now you could go to the inspector and add or remove spawnpoints.
    Knowing where they are picked, you can also replace that code and have 2 sets of points (for 2 teams) or whatever you please.

    Hope that helps.
     
  5. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Thank you tobiass!

    So I have done what you have suggested and seems I am not succeeding in making a spawn position. Clarification on this "Here, I'd throw in a quick fix. Replace the "13" in Random.Range with Respawn.length. Respawn[Random.Range(0, Respawn.length)] will pick one of the available spawnpoints, no matter how many you defined via the Inspector.

    Now you could go to the inspector and add or remove spawnpoints.
    Knowing where they are picked, you can also replace that code and have 2 sets of points (for 2 teams) or whatever you please."

    Do you mean I add a game object in the scene with named length?

    reading it and trying to make some sense to it and greatly appreciating your time and effort

    Max - Thank you for your input I am also looking into that piece of info.

    Fingers crossed.

    Every direction I will take to improve my knowledge
     
    Last edited: Jan 8, 2013
  6. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    I think the best method is to create a game object that is placed in the level like a waypoint or navigation point. Call these "SpawnPoint" game object.
    These can be set to team1 or team2 ..etc. the code above then looks for these SpawnPoints and uses their positions for spawning the players depending on their selected team. You could put checks in to make sure the players don't spawn in the same place at the same time. This is similar to the Unreal Tournament method.

    Max
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    EagerToLearn:
    What I meant to say was: The "SoldierDamageControl" script is part of the scene and in it, you will find the actual list of possible spawn points. You can simply search in the scene's hierarchy and find the script attached to the "EnemiesRef" object.
    Respawn is currently a list of vector3 (positions). This means you can only edit their component values but not assign a object from the scene.
    It's not very convenient to edit the vector3 values in this form. You could turn Respawn into a array of Transforms. This way, you can assign a game object's transform to this list. That will allow you to position empty game objects as spawn points directly into the scene, as suggested by Max. With a simple script, you can find those spawn points and populate the Respawn array with them.
     
  8. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Tobiass and Max

    I will look at the demo scene and locate the code in there and will report back here to my finding.

    Eager

    Update:

    I have found the vector3 (positions) which consists of x,y,z plane values,

    Thank you - Still playing with it
     
    Last edited: Jan 13, 2013
  9. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Just want to know what the reason is for the game to create a clone of the player.

    I am still trying to work out how to modify the spawn point.
    Alas no success however I will keep at it.
     
  10. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    The spawn point locations are in the EnemiesRef.
    They're set up for the Bootcamp scene, so you need to change them for your scene.

    The clone of the player is probably a bug. It's the remote player of the local player being spawned on the same
    scene. look in usephoton.cs for the AddRemotePlayer function and put a check in to make sure the player
    isn't local when spawning the remote player.
     
    Last edited: Jan 18, 2013
  11. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Apologies Max

    What do you mean by putting a check in to make sure the player isn't local.

    Did you mean in code just before the function call I add a check to make sure player isn't local?

    or

    Look in the code and add // to get rid of this check
     
  12. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Max, do you mean like this?

    Code (csharp):
    1. public void AddRemotePlayer(Player player)
    2.     {
    3.         if (Player player == local)
    4.           {
    5.         Transform t = (Transform)Instantiate(playerModel, player.playerRemote == null ? new Vector3(0, -100, 0) : player.playerRemote.pos, Quaternion.identity);
    6.         PlayerRemote playerRemote = t.gameObject.AddComponent<PlayerRemote>();
    7.         playerRemote.player = player;
    8.         player.playerRemote = playerRemote;
    9.         player.playerTransform = t;
    10.         t.position = player.playerRemote.pos;  
    11.         ActorAnimator ActAnimator = t.GetComponent<ActorAnimator>();
    12.         ActAnimator.playerRemote = player.playerRemote;
    13.          }
    14.     }
     
  13. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    Like this I think.

    Max
     
  14. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Thank you Max!

    That did the trick.

    You have saved me from pulling my hair out
     
  15. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    New Question!

    The issue is the player environment, how do I change the settings for darkness or night time that is really dark
     
  16. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I'm pretty bad with visuals, so no answer from me this time :|
    That's a common Unity question, I'd say. Maybe you better post this in some "non Photon" Bootcamp thread to get more attention and help.
     
  17. EagertoLearn

    EagertoLearn

    Joined:
    Dec 27, 2012
    Posts:
    15
    Thank you!
     
  18. kiyuan

    kiyuan

    Joined:
    Jan 9, 2013
    Posts:
    1
    its a awsome demo... im trying to replace DeadSoldier to Ragdoll, but its just instantiate normal soldier and the soldier where its killed never destroy..

    and when soldier1 crouch, in other client he's not crouch.. how can I fix this ??

    sorry for my bad english :/
     
    Last edited: Jan 29, 2013
  19. HomewreckersStudio

    HomewreckersStudio

    Joined:
    Feb 3, 2013
    Posts:
    15
    Hi, would you be willing to supply a default AppID so that we can test it out without having to run our own server? The problem with having to run a custom server is that nobody else is playing! Perhaps if we can try out the default server there will be many games running and we can get a good idea of how it all works in practice :)
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    kiyuan: The crouch state is not synchronized (don't ask me why. i guess it slipped through). You can sync it the way other movement is synced. I can't implement it now so you'll have to dissect movement synchronization. It's a good thing to know, in any case.

    dreaded kane: As the Bootcamp Demo is compatible with the Photon Cloud, you don't have to host at all. It's free for up to 20 concurrent players.
    Register for the cloud and share your AppId with fellow developers or friends to play. We don't really want to run this as public game though. It's a demo by us, not much more.
     
  21. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    Same goes for the aim and jump animations. I just followed the logic of the animations that do work and it was fine. Good learning curve also for future animations.
     
  22. piluve

    piluve

    Joined:
    Mar 17, 2012
    Posts:
    158
    Hello;

    Is the demo working with Unity4?

    See you
     
  23. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Yes, Bootcamp is Unity 4 compatible.
    There are a few warnings about outdated shaders or visual features being used but no scripting issues and it will run just fine.
     
  24. piluve

    piluve

    Joined:
    Mar 17, 2012
    Posts:
    158
    Ok!
    Thanks for the reply!
    See you
     
  25. Aussie Werewolf

    Aussie Werewolf

    Joined:
    Feb 9, 2013
    Posts:
    16
    Sorry for bringing up this 1 week old thread, but is a register/login system possible? any tutorials on how to make one using photon? I know theres a current player name system used in this game but not one that saves stats.
     
  26. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    How can i make a Auto gun which can kill the soldiers?
     
  27. FuryofPhoenix007

    FuryofPhoenix007

    Joined:
    Mar 10, 2013
    Posts:
    3
    Do you know where are the newbie and pro tutorials for multiplayer game??
     
  28. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    Yes but my Turret doesn`t kill the Player (Soldier)
     
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    An account system is not provided by Photon but you can either add your own or use some fitting third party system to achieve what you need.
    Some more Photon Unity Networking tutorials are in the Asset Store (lookup Photon) and the Marco Polo tutorial is a basic one:
    http://doc.exitgames.com/photon-cloud/Marco_Polo_Tutorial
     
  30. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    No, that wasnt my question

    How can i make that the auto gun can damage the Player

    I dont know how the Damage script works
     
  31. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    How works the Damage script of the Player?
     
  32. Max_Damage

    Max_Damage

    Joined:
    Nov 4, 2011
    Posts:
    50
    As far as I can tell:-

    Gun.cs hits a playerremote and sends a message 'Hitsoldier' to that Playerremote through SoldierDamageControl.js .
    usephoton.cs then informs the rest of the playerremotes and the playerlocal that owns the damaged soldier.

    sounds a bit complex . I'll make a diagram.

    Search for SoldierDamageControl.js in the demo and track where it gets its calls from, and where it sends info about the hit.

    Here is the tutorial

    http://doc.exitgames.com/photon-cloud/DemoBootcamp/

    Max
     
    Last edited: Mar 19, 2013
  33. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    Thanks and how can i make now a bullet which can damage the Player as it would be a shot from the Gun
     
  34. zc1415926

    zc1415926

    Joined:
    Jan 16, 2012
    Posts:
    1
    When i download and import the package i got the error message below:

    Assets/Photon/usePhoton.cs(528,13): error CS0030: Cannot convert type `System.Collections.Generic.KeyValuePair<string,ExitGames.Client.Photon.LoadBalancing.RoomInfo>' to `System.Collections.Generic.KeyValuePair<string,RoomInfo>'


    What should i do to fix it ????
    Thank you!
     
  35. merlinwoff

    merlinwoff

    Joined:
    Nov 16, 2012
    Posts:
    10
    Hello

    Can somebody tell my how a can make a 5 minutes session?
     
  36. pakmafia

    pakmafia

    Joined:
    Feb 24, 2011
    Posts:
    43
    did anyone managed to do a mobile version of this demo?
     
  37. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    pakmafia: This demo is not really suited for mobiles. To make it run, you would have to adjust a lot, cause effects and input weren't written with mobile in mind.
    Check out the Angry Bots demo instead. It is for mobiles and we also converted it to multiplayer:
    http://u3d.as/2i9
     
  38. dawntom

    dawntom

    Joined:
    Oct 9, 2013
    Posts:
    4
    I recently saw this demo and found it really a nice example for new learners. But I have one problem when using it: how can I join the server at another computer so that I can start games with friends?
     
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    The demo is built to usually use the Photon Cloud, which is just one server address for any games.
    In your case, you probably want to edit the menu to make users enter some server address before Connect gets called.
    If I recall correctly the code might be in some menu class, buried and inactive.
     
  40. dawntom

    dawntom

    Joined:
    Oct 9, 2013
    Posts:
    4
    thx for the reply ;]
    Still I don't know how to solve my problem. Could you tell me the exact position of the code controlling multiplayer function? And once I find those code,how can I activate them?
    Also, after I Build&Run the demo in web mode, how to join the server from another computer? what address should I type in?
    like this one?
    file:///Users/zzx/NewUnityProject/newproject.html
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    As Photon Server Address you need an IP Address or a host name. It depends on your system how to find that, but knowing it is only the first step. IPs are not just globally "reachable". There are local network and public IPs which are in turn static or temporary. Probably some more.
    So, if you ask these questions, you maybe better start with our hosted service. It's too complex to explain here.

    I can't tell you the exact position of the code and how much it will do for you, sorry. Try to follow my pointers or just start over without those. All you need is to get a user's input of a Photon Server Address which you use to connect to.
     
  42. dawntom

    dawntom

    Joined:
    Oct 9, 2013
    Posts:
    4
    ok
    and one more question:
    how can I use "Photon InstanceLoadbalancing" to setup a service on a macbook?
     
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
  44. dawntom

    dawntom

    Joined:
    Oct 9, 2013
    Posts:
    4
    finally I tried this demo on a PC of Windows7 ,
    but another problem happened:
    after I set up the server's address,
    $???.jpg
    start the loadbalancing as application,
    $???3.jpg
    Build&Run,

    it turns out to be black screen, not into the game screen
    $???2.jpg
    and whats the problem here? How can I solve it?
     

    Attached Files:

    Last edited: Oct 18, 2013
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Your custom server address isn't something you can use. The "http://" prefix is for http only, not for Photon.
    Also, entering a server address and a port means you actually have to setup that random clients from the internet can reach this address, the port and in case of webplayers as client, you also have to add the port (22 ?) to the policy file.
    Discussing this is beyond this thread's scope. Please get in touch through our forum and post in the Server section.
     
  46. Benjamindavid

    Benjamindavid

    Joined:
    Sep 25, 2012
    Posts:
    68
    Hi,

    I'm currently working on a project for my college. I have to complete the project within this month. I urgently need help on the following questions.
    Your spawnpoints idea, I created many spawn points and made the player to spawn at the points randomly after they're killed. Thank you so much. It worked like a charm... But, I have three questions that's really really not working the way I want it and Whenever I tweak the code something somewhere breaks.. and the whole system becomes complex to manage.

    Question 1) How can I make the player spawn at the same spawn points randomly when the player enters the room.. I tried many things but, still I couldn't find a way to do it.

    Question 2) How can I implement a score for each player that gets incremented when the player kills another player and the score is decremented when the player kills himself? I also need to notify all the players about their current score.

    Question 3) I also need to display the high score to all players at the end of the game after a time limit of may be 10 mins.?

    I tried many different ways. But, the code becomes buggy when each code is linked with the other and I don't know how to fix it.

    Please help me with this issue.. Thanks in advance.

    Thanks,
    Benjamin David
     
  47. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Benjamin:
    2: You can use a player property to sync the score per player. Just use SetCustomProperties and pass in a Hashtable with a key "s" for "score" and a value.
    3: You can use a custom property in the room to keep the start time of a round. This way any client could count down the time and one of the players can send a "end of round" RPC making everyone show a summary for a while.

    I can't really help with the other questions. It's near impossible to help with "it's unstable" or similarly open problems. Maybe other students or the teachers can help? There's basically no way around understanding the project you're working with and (sadly) the Bootcamp is pretty complex to start with. Sorry!
     
  48. Benjamindavid

    Benjamindavid

    Joined:
    Sep 25, 2012
    Posts:
    68
    I corrected those problems. Thank you. But, I need to add more than 15 players in a room. But, only 4 players are allowed. I messed with the code and took out the limit for max players in the main menu script. But, I still can't get more than 4 players in the single room. I need upto 15 players to run the game from a single room. What should I do for doing this?

    Thanks,
    Benjamin David
     
  49. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Find all places where CreateRoom get called and check if it sets a 4 player limit.
     
  50. Jiro-Ng

    Jiro-Ng

    Joined:
    Jul 30, 2013
    Posts:
    5
    hi... i have a problem with this
    i try to run a photon server on my device. the demo can connect to the photon server but failed to created room. im still new with photon server, izzit i dint set up the server properly or other issue?