Search Unity

networking animations

Discussion in 'Scripting' started by NikoBusiness, Sep 20, 2014.

  1. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    hey guys i am in progress of making a multiplayer game and i was searching for networking animations,so i have some questions,if you create an animation state system and send only animation state information is it going to suck up bandwith?if yes i reading something like handling animation with client by checking velocity rotation and position. how is that possible in the update function? can anyone give a small example?
     
  2. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    First off, you might be better off asking in the networking forum.

    With regards to networked animations (assuming you're using default networking), the quickest way to get it working is by using OnSerializeNetworkView, and send the players local animator variables if the stream is writing (=the data that is serialized to the network), and then read and set those animator variables within an "if(stream.isReading)" statement.

    Alternately, you could just get Bolt which does all of that for you automagically :)
     
  3. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    this is good for mecanim,in legacy animation i think its going to desync with high ping,im more interested in this :
    Prediction Based Animation
    Post By :
    MWMDragon

    Here is a simple explanation:

    The way that Prediction based Animation works is that the game will set the animation that the player should be playing based on their movement.. If the player is moving forward then the player model will show the walking animation, if they are moving up, show the jumping animation.
    There is no Network overhead (Bandwidth Use) because nothing needs to be sent to the server or the clients, because the animation as it is being predicted and shown by each client playing.
    With the animations already stored in each clients game files, no information needs to be sent. Animations being predicted by all clients playing the game.. job done!


    topic : http://forum.unity3d.com/threads/what-is-the-best-way-to-send-an-animation-over-a-network.133785/

    i cant understand how is it possible because if u store the position in a variable, in the update function it is going to update everytime and change automaticaly.so how is it possible to see if character is moving or not without networking? thats why i need an small example.
     
  4. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PredictAnimation : MonoBehaviour
    5. {
    6.     private Vector3 m_lastPos;
    7.  
    8.     public void Update()
    9.     {
    10.         Vector3 curPos = transform.position;    //get position this frame
    11.      
    12.         Vector3 velocity = curPos - m_lastPos;    //calculate direction from last frame to this frame
    13.         Vector3 descaledVelocity = velocity / Time.deltaTime;    //de-scale by time
    14.      
    15.         float speed = velocity.magnitude;                //length of velocity = speed
    16.         float descaledSpeed = speed / Time.deltaTime    //extrapolated speed over 1 second worth of frames
    17.      
    18.         velocity = velocity.normalized;        /*    equivelant to transform.forward, but relative
    19.                                                 to movement instead of character orientation    */
    20.      
    21.         Vector3 predictedPos = curPos + velocity;                    /*    this is only predicting one frame in front,
    22.                                                                         this is also known as extrapolation                            */
    23.         Vector3 descaledPredictedPos = curPos + descaledVelocity    /*    this is predicting one second worth of frames in front,
    24.                                                                         this is also known as time based extrapolation                */
    25.      
    26.         //velocity = unscaled velocity between last frame and this frame
    27.         //descaledVelocity = velocity extrapolated for 1 second worth of frames
    28.         //speed = speed measurement between last frame and this frame
    29.         //descaledSpeed = speed measurement estimation for 1 second worth of frames
    30.         //predictedPos = extrapolated position for next frame
    31.         //descaledPredictedPos = extrapolated position 1 second into the future
    32.        
    33.         m_lastPos = curPos;        //store position this frame for the next frame
    34.     }
    35. }
    36.  
    Hope this helps! :)
     
    NikoBusiness likes this.
  5. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    this is very good thanks for helping me :)!! but the only problem is that i dont know complex english words and even with translator i cant understand but with some practise and search i will understand! thank you so much again!