Author Topic: I need help with TNet...  (Read 2716 times)

sephiroth_dark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
I need help with TNet...
« on: January 13, 2014, 07:03:56 AM »
So... Hi! My english is very-very bad, sorry...

Now i create some multiplayer project. In start of my work i used standart Unity multiplayer functions... But it's a lot of time, lags, bugs, and a lot of some ****

And so... Now i try create a multiplayer project on the TNet system. This is very good framework! But when i create player prefab, i controll all players. I can't delimit player controll.

I create a mmorpg game and tutorials with cubes and capsules not helped me... I'm stupid... i now =(

Maybe anybody help me with problem or send me simple example with third person controller?

I need to synchronize movement of third person controll chars on the terrain.

gg67

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 66
    • View Profile
Re: I need help with TNet...
« Reply #1 on: January 13, 2014, 04:50:20 PM »
The issue is that when you create a networked player, you aren't turning off the scripts on the player gameobject that only the owner of the player should be using.

You're going to need to turn on/off different components on your Player objects depending whether or not they are you or another networked player. You can check to see if the Player that the script is attached to is "you" by using TNet's tno.isMine. Once you know if the player is "you" then you can turn on components like CharacterMotor or MouseLook. If the player is not you, then you'd want to turn off CharacterMotor or MouseLook.

For example, assume this code is in a script called "NetworkedPlayer.cs" and is attached to your player prefab. You'd have the CharacterMotor component on your player prefab disabled. Then, in code, you'd enable it IF the player you are creating isMine.

  1. void Start() {
  2.     if(tno.isMine) {
  3.         GetComponent<CharacterMotor>().enabled = true;
  4.     }
  5. }
  6.  

Hope that helps!
 

sephiroth_dark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: I need help with TNet...
« Reply #2 on: January 14, 2014, 01:33:20 PM »
Thx, bro! You save me =))

I write this code..


NetworkPlayer.cs listing:
  1. using UnityEngine;
  2. using System.Collections;
  3. using TNet;
  4.  
  5. public class NetworkedPlayer : TNBehaviour {
  6.         Vector3 Vertical;
  7.         Vector3 Horizontal;
  8.         public float moveSpeed = 6.0f;
  9.         public float rotSpeed = 4.0f;
  10.         // Use this for initialization
  11.         void Start () {
  12.                 if(tno.isMine) {
  13.                         GetComponent<CharacterMotor>().enabled = true;
  14.  
  15.                 }
  16.                 else
  17.                 {
  18.                         GetComponent<ThirdPersonController>().enabled = false;
  19.                         GetComponent<ThirdPersonCamera>().enabled = false;
  20.  
  21.                 }
  22.         }
  23.        
  24.         // Update is called once per frame
  25.         void Update () {
  26.                 if (!tno.isMine)
  27.                 {
  28.                 transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
  29.                 transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime);
  30.                 }
  31.         }
  32. }
  33.  

And it work's... But i now work on synchronize other objects. If i meet some troubles, can i ask questions in PM?

gg67

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 66
    • View Profile
Re: I need help with TNet...
« Reply #3 on: January 14, 2014, 03:40:46 PM »
Sure. But if you think others may benefit from your problems, post here so if anybody has a similar question they can look here!

sephiroth_dark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: I need help with TNet...
« Reply #4 on: January 15, 2014, 12:29:36 PM »
Thank you very much! My dear friend! =)