Author Topic: TNet + Standard Unity FPS controller  (Read 4545 times)

Jake_Kydd

  • Guest
TNet + Standard Unity FPS controller
« on: August 27, 2013, 11:45:58 AM »
Hello there,

for my next game I plan to add a multiplayer mode and a coop mode to my existing single player setup.

I am currently unsure whether TNet or Photon would be the better choice to do this. Given that TNet is much cheaper than Photon, I decided to give this a try and so  I followed your tutorial video on how to setup TNet from scratch.

Well my FPS setup uses the standard FPS Input + Character Motor + Mouse Look scripts. If I am not entirely mistaken (and please forgive me, I never touched the networking part of Unity or TNet before) all I had to do was the following to add basic multiplayer support to the game:

1. Create a TN Manager object (script)  + TN Auto join in the main menu scene

2. Add the Player Prefab to the TN Manager array. Call the Tnets connect function via the 'Start Game' button.

3. Declare the Game Scene in Auto Join (+ a few other parameters).

4. Go to the actual game scene and add TN Create -> assign your Player Prefab to the array and uncheck 'persistent'.

5. Edit the Player Prefab: Add TNObject and TNAutoSync to it. Set TNAutoSync to UnityEngine.Transform position; updates per second = 20; and check Only Owner Can Sync.

6. Following the tutorial I added a custom cs script to the prefab with the following code:
  1. public class Game_Player : MonoBehaviour {
  2.  
  3.         // Use this for initialization
  4.         static public Game_Player instance;
  5.         void Awake() {
  6.                 if (TNManager.isThisMyObject){
  7.                 instance = this;
  8.                 }
  9.         }
  10. }

7. Start the server, start a few clients and check out what's happening!

Now starting the server (external exe) and connecting to it with a few clients works just fine. However each client is controlling each avatar at the moment he joins the server.
It's like everyone is controlling all players at the same time... I don't understand this as I checked the 'Only owner can sync' checkbox at the AutoSync script for the Player Prefab and all Player Prefab (Clone)s do have a unique TNObject ID...

Any help with this is highly appreciated! I have the feeling that I made a pretty obvious and simple mistake...

Best Regards,
Jake

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet + Standard Unity FPS controller
« Reply #1 on: August 27, 2013, 12:31:12 PM »
You likely forgot to add a check for "tno.isMine" before doing your input handling logic, so your code runs on all the avatars at once.

Jake_Kydd

  • Guest
UPnP External Access
« Reply #2 on: August 31, 2013, 04:44:10 AM »
Thank you very much Aren,

adding this simple check before handling the input logic solved my issue!

Might I hijack this thread for another issue of mine? (I don't want to spam this board with threads).

When I start up the Server.exe I am getting 3 different IPs, External, Internal and Gateway.

For internal testing I used the internal IP to connect my local clients and it works out of the box.

Next step would be to switch to the external IP address if I am not mistaken.

Doing so, TNet server tells me that all needed ports have been opened via UPnP successfully, by logging into my router I can verify this, the ports are open and they are pointing to the server IP address.

However if I point my clients to connect to the external IP, neither can my local devices nor external devices connect. "Unable to connect" is all I get...

Is there anything I can do about this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet + Standard Unity FPS controller
« Reply #3 on: August 31, 2013, 12:25:38 PM »
Some routers, like my ASUS router don't allow loopback addressing (connecting to a LAN computer using a WAN address). Just ask someone from the outside to connect to you.