Problems with Switching One Room to Another via Portals.

My idea is having an initial Photon Room as "Town" with portals that will lead you into another Photon room as "FightingAreas".

I've been seeing mixed answers from the forum here on how exactly how to deal with portals. My original attack plan was to make the areas separate Photon rooms. I then saw a forum thread that specifically had the same problem as I solved that problem by making PhotonNetwork.automaticallySyncScene false, then using SceneManager.LoadScene.

I have managed to do it this way, but have found out that since they're still in the same Photon Room, if Player A and Player B are in separate scenes, Player A can still see Player B move around and visa versa.

I looked around some more to find the best solution to my problem was to separate the scenes in different Photon Rooms.

My Problem: The rooms are instantiated, portal can move the player from the "Town" room to the "FightingArea1" room. However, if Player A goes through the portal, Player B teleports as well after Player B tries to move. Same happens with Player B.

Code:
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player" && other.gameObject.GetComponent().isMine)
{
Debug.Log("Collision Detected with " + other.gameObject.name);
UsePortal(PortalLeadsTo);
Debug.Log("OnTriggerEnter: UsePortal(" + PortalLeadsTo + ")");
}
}

void UsePortal(string PortalName)
{
Debug.Log("UsePortal(" + PortalName + ")");
isTeleporting = true;
if (isTeleporting)
{
PhotonNetwork.LeaveRoom();
Debug.Log("UsePortal: LeaveRoom()");

isTeleporting = false;
}
}

public override void OnLeftRoom()
{
Debug.Log("OnLeftRoom()");
SceneManager.LoadScene(PortalLeadsTo);

Debug.Log("UsePortal: Loadlevel(" + PortalLeadsTo + ")");
}

public override void OnConnectedToMaster()
{
Debug.Log("OnConnectedToMaster()");
PhotonNetwork.JoinRoom(SceneManager.GetActiveScene().name);
}


public override void OnJoinedRoom()
{
Debug.Log("PHOTON ROOM NAME: " + PhotonNetwork.room.Name);
Debug.Log("# OF PLAYERS: " + PhotonNetwork.room.PlayerCount);
}

public override void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer)
{
PhotonNetwork.SetMasterClient(otherPlayer);
}

public override void OnDisconnectedFromPhoton()
{
Debug.LogWarning("WE DISCONNECTED!");
}

public override void OnPhotonJoinRoomFailed(object[] codeAndMsg)
{
Debug.Log("OnPhotonJoinRoomFailed()");
Debug.Log("RoomName: " + SceneManager.GetActiveScene().name);
PhotonNetwork.CreateRoom(SceneManager.GetActiveScene().name, new RoomOptions() { MaxPlayers = 20 }, null);
Debug.Log("OnPhotonJoinRoomFailed(): CreateRoom");
}

Comments

  • Going to leave this unsolved.
    Will just proceed to keep the game one room.