Hey guyz. I’m currently work on my little mmo game with using unity3d network system. server side is completed which includes mob spawns and player movement such things. also i did the smooth player movement with onserializenetworkview. but i have one problem such as animaton. i use mecanim animator system for my players characters. how can i serialize mecanim animators between clients? btw pls don’t talk about photon.
here is my movement serialize code;
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Vector3 syncVelocity = Vector3.zero;
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
if (stream.isWriting)
{
syncPosition = this.transform.position;
stream.Serialize(ref syncPosition);
syncPosition = this.GetComponent<CharacterController>().velocity;
stream.Serialize(ref syncPosition);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncVelocity);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncEndPosition = syncPosition + syncVelocity * syncDelay;
syncStartPosition = GetComponent<CharacterController>().transform.position;
}
}
here is my animation code;
void Movement()
{
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
Vector3 velocity = new Vector3(h, 0, v);
_controller.Move(velocity * _moveSpeed * Time.deltaTime);
_anim.SetFloat("Horizontal", h);
_anim.SetFloat("Vertical", v);
if (!Mathf.Approximately(h, 0f) || !Mathf.Approximately(v, 0f))
{
_anim.SetBool("Motion", true);
}
else
{
_anim.SetBool("Motion", false);
}
}