Author Topic: Animation Sync (not mechanim) and other help :-)  (Read 2893 times)

nuverian

  • Guest
Animation Sync (not mechanim) and other help :-)
« on: May 11, 2013, 02:25:24 AM »
First of all great product really. Made my day :-)

I'd welcome some clarification on some matters please:

1)What is the good way of syncing animations?

2)I've made a simple cube for each player to move around with WASD and naturally I do this in Update with Translate. For each player to move only his/her cube, is the correct way of doing this by | if (!tno.isMine) return; | in the Update function prior to the movement code? It works, but dunno if its the correct thing to do.

3) I get some jeerky movement (positions) in my example with the cubes. Why would that be?

Thanks :-)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animation Sync (not mechanim) and other help :-)
« Reply #1 on: May 11, 2013, 12:48:51 PM »
2. Yup that's fine.

3. Separate physics from renderer. Look at what I did with cubes in the 2nd example.

1. When you Play an animation, consider sending an RFC instead to everyone that will play the animation inside it.

nuverian

  • Guest
Re: Animation Sync (not mechanim) and other help :-)
« Reply #2 on: May 11, 2013, 09:10:34 PM »
So I've tried to sync things without the auto sync and I just completely failed to achieve even the simplest thing there possible can be. I feel like there is something I am totaly missing here, allthough I've seen the tutorial like 3 times and read all the posts here. So I have this extremelistic (my own word) thing for testing:

  1. #pragma strict
  2. import TNet;
  3.  
  4. class PlayerTest extends TNBehaviour{
  5.  
  6.         var moveSpeed:float;
  7.         var rotSpeed:float;
  8.  
  9.         function OnEnable(){
  10.  
  11.                 if (tno.isMine)
  12.                         Camera.main.GetComponent(SmoothFollow).target = this.transform;
  13.         }
  14.  
  15.         function Update(){
  16.  
  17.                 if (!tno.isMine)
  18.                         return;
  19.  
  20.                 transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
  21.                 transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime);
  22.  
  23.                 if (Input.GetKeyDown(KeyCode.Space))
  24.                         tno.Send("PlayAnimation", Target.All);
  25.         }
  26.  
  27.         @RFC
  28.         function PlayAnimation(){
  29.  
  30.                 animation.Play();
  31.         }
  32. }
  33.  

It's ok about the animation and plays just fine as you suggested. Now I COMPLETELY fail to understand how to (custom) sync the transforms for such a behaviour...really. I mean...  :o

Also regarding my previous question number 3. The cubes have neither rBody, nor even a collider and I was getting a choppy movement (for the other player cubes) when I was using the auto sync script. Please help me understand what I am missing here  :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animation Sync (not mechanim) and other help :-)
« Reply #3 on: May 12, 2013, 12:52:30 PM »
You're already calling a remote RFC function called PlayAnimation. All you have to do is add parameters to it like so:

tno.Send("PlayAnimation", Target.All, transform.position, transform.rotation);

Then add a Vector3 and a Quaternion parameter to your PlayAnimation function and set the transform.position and transform.rotation to those values.

nuverian

  • Guest
Re: Animation Sync (not mechanim) and other help :-)
« Reply #4 on: May 12, 2013, 01:53:36 PM »
So something like this:

  1. #pragma strict
  2. import TNet;
  3.  
  4. class PlayerTest extends TNBehaviour{
  5.  
  6.         var moveSpeed:float;
  7.         var rotSpeed:float;
  8.  
  9.         function OnEnable(){
  10.  
  11.                 if (tno.isMine)
  12.                         Camera.main.GetComponent(SmoothFollow).target = this.transform;
  13.         }
  14.  
  15.         function Update(){
  16.  
  17.                 if (!tno.isMine)
  18.                         return;
  19.  
  20.                 transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
  21.                 transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime);
  22.  
  23.                 tno.Send("UpdateTransforms", Target.All, transform.position, transform.rotation);
  24.         }
  25.  
  26.         @RFC
  27.         function UpdateTransforms(pos:Vector3, rot:Quaternion){
  28.  
  29.                 transform.position = pos;
  30.                 transform.rotation = rot;
  31.         }
  32. }
  33.  

Works. Also should such calls in the Update be made with SendQuickly better?

Thanks for replies

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animation Sync (not mechanim) and other help :-)
« Reply #5 on: May 13, 2013, 01:17:45 AM »
You shouldn't be doing it on Update. You should be synchronizing periodically, every so often. Update runs every frame, so if you have 1000 FPS that's 1000 updates -- way too much. The best time to send an update, is when something changes -- generally this means sending it after user input changes something.

nuverian

  • Guest
Re: Animation Sync (not mechanim) and other help :-)
« Reply #6 on: May 14, 2013, 02:18:06 AM »
Yeah, I thought as so. I will look into how this is properly done then. I understand its beyond the scope of Tnet but rather general networking stuff.
Thanks