Author Topic: Joining channel, stay in same position  (Read 2322 times)

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Joining channel, stay in same position
« on: October 07, 2013, 05:09:37 PM »
Ive noticed some buggs when i try to make a "channal" changeing script. It's 2 clients who are in the same channel and scene. then theres a script that looks like this:
  1. public class changeChannel : MonoBehaviour {
  2.        
  3.         void OnGUI(){
  4.                 if(GUI.Button(new Rect(20,20,100,40),"1")){
  5.                         joinChannel(1);
  6.                 }
  7.                 if(GUI.Button(new Rect(20,80,100,40),"2")){
  8.                         joinChannel(2);
  9.                 }
  10.         }
  11.        
  12.         void joinChannel(int channelID){
  13.                 TNManager.JoinChannel(channelID,null);
  14.         }
  15. }
verry simple, i make the joinchannel level to null so you don't have to respawn at a new position everytime i join that channal, I wan't to make so everyone loads me in when i join the channel and the same thing goes for me, when i join the channel: load every objects in that channel. The reason why i dont wan't to load a level is becouse you should be able to walk
into zones and keep your current position while entering a new channel
What happens when i change the channel:
1. The player who presses change channel still have the old game objects "may be a reason for none level load.. I dunno".
2. THe player that pressed channel change dissapears for the rest of the players in the old channel.
3. The player that leaves the old channel and joins an empty can walk around and wont respawn(as wanted), but when the player enters the channel with players on it so will he respawn.
I'm using the script TNAutoCreate and then the player is inside it
« Last Edit: October 07, 2013, 05:16:48 PM by addebooi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Joining channel, stay in same position
« Reply #1 on: October 08, 2013, 01:05:34 AM »
1. Yes, you are not switching levels, so there is no "clean slate" for you. You keep whatever you have -- that's the idea behind passing null for the level name.
2. Of course he does. You can only be in one channel at a time.
3. Respawn? I don't understand what you mean. TNet doesn't do any respawning, so that's your logic that needs adjusting.

Also keep in mind, the whole point of loading a level is so that you end up in the same state as all the other players -- a clean slate, if you will -- and it's not possible to do if you are already in the level.

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Joining channel, stay in same position
« Reply #2 on: October 08, 2013, 01:57:15 AM »
1. Ive set an object with the script "TNAutoCreate" in the level. which spawns the player, and when i join an empty chanel nothing happens(as wanted). But when i join a channel with a
player the script is called again, even though it's destroyed(not wanted). And i don't really know why that's happening becouse the script that instatiates the gameobject is destoroyed. That Gameobject is only "preset" in the level.

In this script i describe what happens when a player joins the network. He get's the position and the rotation from all GameObjects(players gameobjects) in that channel.
  1. [RFC(254)]
  2.         public void getPositionAndRotation(Vector3 pos, Quaternion rotation){
  3.                 rotateTo = rotation;
  4.                 transform.position = pos;
  5.         }
  6.        
  7.         void OnNetworkPlayerJoin(Player p){
  8.                 Debug.Log("Player joined channel");
  9.                 tno.Send(254,p,transform.position, transform.rotation);
  10.         }
So the only thing that goes pretty much wrong here is that he is "re instatiated" everytime he joins the channel with players.

2. And can i somehow get all the gameobjects that are instatiated through the network?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Joining channel, stay in same position
« Reply #3 on: October 08, 2013, 03:08:47 AM »
Let me put it this way... Passing 'null' for level name is for advanced users who prefer to manage the state of their objects themselves. TNAutoCreate creates an object in Start(). In your case Start() is called long before you actually join the channel.

It's a very small script -- look at what it does inside. It's literally 4 lines of code.

Long story short -- either start by specifying a level to load on channel join, or don't use TNAutoCreate. Use TNManager.Create in OnNetworkJoinChannel() instead.