Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: tstack on October 14, 2016, 04:25:18 PM

Title: Odd occurrence on second player client join - 2nd player takes 1st player place.
Post by: tstack on October 14, 2016, 04:25:18 PM

Hello,

I can play as a single player, then join with a second device/client. But when I join with the second client, my character, name color and all appears, then shifts to where player one was on the 2nd client screen and I cannot control them.

Any thoughts here appreciated, my project is due in just over a week now.

Thanks,
tstack
Title: Re: Odd occurrence on second player client join - 2nd player takes 1st player place.
Post by: cmifwdll on October 14, 2016, 07:54:05 PM
I think what's happening is your camera is on the player prefab, and so when the second player joins Unity starts rendering the newly-spawned second camera. If that's correct then you've got a few options:
1. Decouple the camera from the player prefab (you'd have to write some code to position the camera accordingly, probably not ideal)
2. Delete the camera from the prefab on spawn if tno.isMine is false (make the camera its own child gameobject so you can do this in one simple Destroy() call from the Awake event)
3. Adjust the camera's depth property (this controls the order cameras are rendered in)

Keep in mind that each camera in the scene is rendered at all times, so option 3 probably isn't ideal. I personally go with option 2, but it feels wrong so maybe someone else has a better solution?
Title: Re: Odd occurrence on second player client join - 2nd player takes 1st player place.
Post by: tstack on October 15, 2016, 04:54:57 PM

Hi thanks cmifwdll - these are great insights - the prefab is not coupled to the camera however, it attaches after TNet instantiation - it is the same way the TNet demo files work.

Also, I should add that I got this working around March and TNet has worked flawlessly ever since. However I made changes to my game at the end of August, then went on an entire month fixing the inventory system.

I don't think I tested those August changes before I worked on the inventory system. They included things like adding a player name and the player selecting a color.

Why it suddenly applies to the 1st player on the joining client (from the 1st player client this is not indicated - everything still looks normal) I am guessing because of my handling of variables.

The game, having applied the name and color to the 1st player on the 2nd players client screen (iOS) never actually instantiates the 2nd player. I am guessing it errors out at this point.

I'm not sure what to do since feedback from the iOS platform is minimal. I am going to try commenting out my "Options Menu" code from August.




Title: Re: Odd occurrence on second player client join - 2nd player takes 1st player place.
Post by: lynohd on October 16, 2016, 03:02:33 PM
Shouldnt just enabling/Disabling components accordingly do the trick?

  1. if(tno.IsMine)
  2. {
  3. CameraComponent.enabled = true;
  4. }else {
  5. CameraComponent.enabled = false;
  6. }
Title: Re: Odd occurrence on second player client join - 2nd player takes 1st player place.
Post by: ArenMook on October 17, 2016, 10:28:14 PM
You'll need to post some code of what you're doing, but as cmifwdll said you're likely simply not doing a proper check on start.