Author Topic: Tnet and Unity's FPSController  (Read 3081 times)

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Tnet and Unity's FPSController
« on: February 04, 2016, 03:49:03 PM »
Anyone had any luck using unity's Standard Asset FPSController?

If I set it up with a TNObject script and TNAutoSynch on the base transform, all is well, but when I try to add the same thing to the "head", in their case what they've labeled "FirstPersonCharacter", (adding either a rotation or localRotation parameter to TNAutoSync) I get "Mismatched number of parameters sent via TNAutoSync!" errors every time I rotate the head transform.

I'm guessing it has to do with the way Unity has the whole prefab set up and I'll just have to create a character from scratch, but I thought I'd ask if anyone else has had success with this first.

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Tnet and Unity's FPSController
« Reply #1 on: February 04, 2016, 05:40:28 PM »
Okay, after a lot more testing and experimentation. I believe it's because I was using AutoSync when I should have been using Sync Rigidbody. I did the tests on a completely new hand-made player, but I'm guessing that would fix it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet and Unity's FPSController
« Reply #2 on: February 04, 2016, 09:38:14 PM »
You can only have one TNAutoSync per TNObject. If you have nested TNObjects, only root TNObject actually gets an ID to work with, so only one TNAutoSync can be used as well.

In general, TNAutoSync is a convenience script to be used for prototyping. It's a much better idea to create your own RFCs and send data when you need it. I always recommend a 3-step approach:

1. Poll Input.GetAxis / Input.GetKeyDown etc, set local values. If these values change sufficiently (more than 5-10% since the last send), tno.Send an update to sync this input across all clients. Don't send more than 5 times per second.

2. Send transform's position/rotation and rigidbody's velocity infrequently -- every couple of seconds.

This approach will mean that you are sending very little data and only when it changes sufficiently. In between of the infrequent updates, all clients will run a local simulation based on the input values they have. In most cases this means that there won't be much of a difference to correct when the infrequent sync finally arrives.

End result? Low bandwidth, smooth results.

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Tnet and Unity's FPSController
« Reply #3 on: February 05, 2016, 03:01:48 PM »
That makes sense. Thanks :)

It's been a while since I've used Tnet and I never knew about the "one TNAutoSynch per object" rule.