i want to synchronize the character movement in different clients,
while i got an problem here.
The script below is attach at the other players' characters,
say if you are player A in client A, then the player B,C,D.....' characters will have the below script.
My problem is that:
When player A in client A moving forward at the same time using a normal attack.
for example, pressing key "up arrow" and "z" (without key up).
In client A, it give me the expected result,i.e. player A standing at the current position and playing the normalatt animation repeatedly without moving.
While when the above data send to the server and receive by player B,
player A character in client B, did play the normalatt animation , but when the animation end, SOMETIMES it will move forward before the animation replay.
How can i correct the script so that player A in client B won't move forward before player A in client A key up the key "z"
void Update () {
if(moving){
transform.position += transform.forward*speed ;
}
}
//and event which get response from server
void updatecharactermovement(int playeruid,string command,float rotx,float roty,float rotz){
//if an character move, change it direction
if(command=="move"){
if(playeruid==this.playerid){
transform.eulerAngles=new Vector3(rotx,roty,rotx);
moving=true;
}
}
//if a character stop, reset it position
if(command=="stop"){
if(playeruid==this.playerid){
transform.position=new Vector3(rotx,roty,rotz);
moving=false;
}
}
}
//function which play the character skills
void updatecharacterskill(int playerid,string skill){
if(playerid==this.playerid){
if(skill=="normalatt"){
animation.CrossFade("normalatt");
StartCoroutine(attacting(skill));
}
}
}
// allow the character continue to move until the skill animation end
public IEnumerator attacting(string skill){
moving=false;
animation.CrossFade(skill);
yield return new WaitForSeconds ( (float) animation[skill].length);
moving=true;
}
i think my problem is related to WaitForSeconds,
will there error if attacting function call the second time when the first call not yet end? – brian661 Jan 03 '14 at 13:23