Animation Syncing problem.

Options
Here is the code I wrote, but it isn't working how I want it to:

public class PlayerSync : Photon.MonoBehaviour {
	
	public int AnimIDSend;
	private int AnimIDRec;
	public string [] AllAnimations;
	

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {

            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
	  stream.SendNext(AnimIDSend);

        }
        else
        {
           
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
		AnimIDRec = (int)stream.ReceiveNext();

      
        }
    }

    private Vector3 correctPlayerPos = Vector3.zero; //We lerp towards this
    private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this

    void Update()
    {	
			
        if (!photonView.isMine)
        {
           
            transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
            transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
			transform.animation.CrossFade(AllAnimations[AnimIDRec]);
	
    }

}
}



A bunch of messed up things happen, like when I play an attack animation, sometimes it shows the other character playing the attack animation when they aren't. It also infinitely loops into the attack animation.

The walk animation works half way, it syncs walking, but the animation speed isn't correct, how should I go about doing that?

Any better ways to do animation?

Comments

  • Tobias
    Options
    The OnPhotonSerializeView is called several times/second. You don't want to start or crossfade the anim that often into the running one.
    Check out the Marco Polo tutorial. We use an animation state (or character movement state or whatever you call it) and when that *changes*, we play another animation. That's probably the secret.

    http://doc.exitgames.com/photon-cloud/M ... o_Tutorial