Author Topic: Using Invector Third Person Controller with TNet  (Read 890 times)

acronyte

  • Newbie
  • *
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 46
    • View Profile
Using Invector Third Person Controller with TNet
« on: April 22, 2017, 08:59:37 AM »
Has anyone successfully used Invectors third person controller from unitys asset store with Tnet?

I've been trying for days to get this asset working along with Tnet....but with no success.

Now I know that I'm supposed to be syncing a controllers input with Tnet and the characters animation will automatically follow, but I just cant seem to get it working...

The Invector controller has three separate scripts which control a characters movement (thirdpersonmotor.cs, thirdpersonanimator.cs and thirdpersoncontroller.cs)

I've been only editing the 'thirdpersoncontroller.cs' to work with Tnet with the code below:
Invectors original code (the 'input' part')
  1.  /// <summary>
  2.         /// CONTROLLER INPUT - gets input from keyboard, gamepad or mobile touch to move the character
  3.         /// </summary>
  4.  
  5.                 public void ControllerInput()
  6.         {
  7.             if (inputType == InputType.Mobile)
  8.                 input = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"), CrossPlatformInputManager.GetAxis("Vertical"));
  9.             else if (inputType == InputType.MouseKeyboard)
  10.                 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
  11.             else if (inputType == InputType.Controler)
  12.             {
  13.                 float deadzone = 0.25f;
  14.                 input = new Vector2(Input.GetAxis("LeftAnalogHorizontal"), Input.GetAxis("LeftAnalogVertical"));
  15.                 if (input.magnitude < deadzone)
  16.                     input = Vector2.zero;
  17.                 else
  18.                     input = input.normalized * ((input.magnitude - deadzone) / (1 - deadzone));
  19.             }
  20.  
  21.         }
  22.  
  23.  

Ive edited this to show:

  1. public void ControllerInput()
  2.         {
  3.             if (inputType == InputType.Mobile)
  4.                 input = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"), CrossPlatformInputManager.GetAxis("Vertical"));
  5.             else if (inputType == InputType.MouseKeyboard)
  6.                 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
  7.             else if (inputType == InputType.Controler)
  8.             {
  9.                 float deadzone = 0.25f;
  10.                 input = new Vector2(Input.GetAxis("LeftAnalogHorizontal"), Input.GetAxis("LeftAnalogVertical"));
  11.                 if (input.magnitude < deadzone)
  12.                     input = Vector2.zero;
  13.                 else
  14.                     input = input.normalized * ((input.magnitude - deadzone) / (1 - deadzone));
  15.             }
  16.                         tno.Send (1, Target.OthersSaved, input);
  17.         }
  18.  
  19.                 [RFC(1)]
  20.                 void Move(Vector2 i){
  21.                         input = i;
  22.                 }
  23.  

I've added Tnets original autosyncrigidbody script and it works...the character sync but not their animation...

I'm assuming Invectors other two files need to be edited?

Can someone guide me in the right direction? Ive attached the three Invector controller files if anyone is willing to help me out...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Using Invector Third Person Controller with TNet
« Reply #1 on: April 22, 2017, 12:29:36 PM »
Sync of input is very simple. Basically if there are 3 axes, they should be declared on the class that actually uses them -- such as your player object. This way the multiple controllers will be responsible for setting this value on the player, and this player script will also do the synchronization as necessary.

For synchronization I favor the infrequent approach -- check inequality against the last saved value. If it's within the accepted threshold (I usually stick with 5%), just wait until enough time has passed for the change to be meaningful. If the change is significant (for example 0% to 100% as is often the case with AI), sync it right away.

Either way, send nothing if the values haven't changed.

Don't try to sync anything unless this is your own player.

Make sure that controllers will only set axes on the player object, and won't try to do it for other players's objects.

Since the player object will do the sync itself, and only if the player owns this object, all other players will be updated automatically.