Change Scenes for RPG

Michael_Watkins
edited October 2 in Any Topic & Chat

If there is another way of doing this please let me know in a comment


What I have:

2 players start a party to play the game "Party1" is the name of the party. The both start in Scene 1 in the street. One gets to a door and goes inside of the building (Scene 2). Player 1 sees player 2 leave scene1 at the doorway. Player2 ends up in scene 2 inside the building. Player1 then goes through the same door and loads scene2. Player2 sees player1 enter scene2.

How I did it:

I set up a trigger to change rooms. It contains the name of the scene to change to and a name for the spot you arrive at. These are given to a game manager then the player is told to leave the photon room. Once we get the leftroom() callback just use a normal unity scenemanager to load a scene called "SceneLoader" in here we take the name of the party and combine it with the name of the scene to go to (Party1Inside) then we create (or join if someone in that party is already in that room) a room with the combined name. then we use photon to join the scene by scene name stored in the game manager. Inside the new room we use photon to instantiate to the location provided in the game manager. Combining the party name to room name means only people from that party will see each other in that specific scene.

It works great. Only drawback now is that when they go to different rooms naturally photon voice doesn't work across rooms.

Comments

  • You could have Voice "rooms" for the party or for the instance of the scene/room you use in PUN.

    Voice has a workflow to follow PUN's room changing but it may disregard the system you setup. So you may have to tell Voice, which room to join (too). See "ConnectAndJoin.cs" utility script for example (or check the API reference for Voice).

  • but i thought voice only worked in the room you are in. Are you saying i can have a pun room and a voice room both running side by side?

  • Yes, Voice uses a separate connection and even a separate AppId. Rooms for Voice don't have to map to other rooms 1:1 but of course it makes sense you can talk to people you see / interact with as well.

  • thank you. will do some research. always thought two players in different pun rooms wouldnt be able to hear each other.

  • Michael_Watkins
    edited October 9

    ok im lost. every youtube video and the documentation tells me this shouldnt work

    2 players join a pun room1, they then enter unity scene1

    1 player leaves the pun room and leaves the scene then joins pun room2 and unity scene2. everything is telling me his voice connection to player 2 still in pun room1 and unity scene1 will be lost. can you point me to where in the documentation or a tutorial i can get it to work

    player1's voice wouldnt know where player2 is to be able to connect to him

  • I am actually not the Voice "pro" here but it's definite that Voice does not have to use a room that is matching PUN. This may require some modification of Voice. I'll ask a colleague to chime in.

  • If you are using PhotonVoiceNetwork, the voice room client state will follow the PUN room client state and streams will be bound to network objects in the scene.

    To avoid this, use VoiceConnection instead of PhotonVoiceNetwork. Then voice and PUN client will run independently.

  • Just curious though. the method im using to make an RPG style game. Is it how others do it or is there a better way?

  • If your players change rooms but want to talk to the same party, no matter where players are in-game, then this is the only way.

    If it works, it is usually a valid way to solve the problem.