Syncronized animations on Multiplayer

Hi everyone! I already downloaded the Unity’s Networking example and examinated the TPS Auth but I’m not still able to do it!

I created a simple robot with only one animation (walk). And this script for make it walk

function Update () {

if(networkView.isMine){

    if (Input.GetKey("w")){
        animation.Play("walk");
        transform.Translate (Vector3(0,0,3)*Time.deltaTime);
}
        if (Input.GetKey("a")){
        transform.Rotate (Vector3(0,-20,0)*Time.deltaTime*5);
}
        if (Input.GetKey("d")){
        transform.Rotate (Vector3(0,20,0)*Time.deltaTime*5);
}
}
}

What I need is an help to syncronize this animation at others players! Now, in my istance, I can see the robot walking properly but other clients see my robot move without walk (as a sliding). Can you tell me what I need to do it? Thanks

688079--24747--$robot.JPG

You need to use RPC calls to and trigger the animatio on the remote players

Hi appeals! Ok I found a useful script (use RPC) and I modify it! Now I have:

public var charMesh : Animation;

public var animations : Array = new Array();

animations[0] = "idle";

animations[1] = "cammina";



var currentAnimation : String;



function Update () {



if(networkView.isMine){



    if (Input.GetKey("w")){

        transform.Translate (Vector3(0,0,3)*Time.deltaTime);

        setAnimation("cammina");

}

else

{

 setAnimation("idle");

 }

        if (Input.GetKey("a")){

        transform.Rotate (Vector3(0,-20,0)*Time.deltaTime*5);

}

        if (Input.GetKey("d")){

        transform.Rotate (Vector3(0,20,0)*Time.deltaTime*5);

}



}

}



function Start() {



	charMesh.animation.Stop();

	charMesh.animation.wrapMode = WrapMode.Loop;

	

	charMesh.animation["cammina"].layer = 1;

}



function setAnimation(aState:String) {

	

	//Debug.Log("setting animation state:"+aState);

	

	if(networkView.isMine) {

		

		if(currentAnimation != aState) {

			

			var aName : String;

			for(var i=0; i<animations.length; i++) {

				if(animations[i] == aState) {

					

					networkView.RPC("setAnimationState", RPCMode.Others, i);

					setAnimationState(i);

					currentAnimation = aState;

					return;

				}

			}

		}

	}

}





@RPC

function setAnimationState(aStateIndex : int) {

	//Debug.Log("setAnimationState called with index:"+aStateIndex);

	charMesh.animation.CrossFade(animations[aStateIndex], 0.2);

}

I feel to be near at the solution but I’ve still 2 problems

With this code the transform.Translate don’t work so my robot only go in direct line.
And the second problem is the the walk animation don’t stop although I stop press “w”

Can you help me to understand how to fix these? Thanks

help :slight_smile:

Have you debugged your script ? Thats the first thing you should be doing.
Try and figure out if you press a key, they animations is triggerd and if the remote receives the RPC.

Yes in the remote the animation is triggered and the remote receives the RPS!

This is what appened: http://www.youtube.com/watch?v=kdlLInKz8k0