0
\$\begingroup\$

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"

an video showing my problem

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;
    }
\$\endgroup\$
4
  • \$\begingroup\$ gamedev.stackexchange.com/questions/552/… \$\endgroup\$
    – wes
    Commented Jan 3, 2014 at 12:58
  • \$\begingroup\$ i have read that before and i think that is not my problem i believe. 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? \$\endgroup\$
    – brian661
    Commented Jan 3, 2014 at 13:23
  • \$\begingroup\$ there isn't enough information in your post to determine what your problem is \$\endgroup\$
    – wes
    Commented Jan 3, 2014 at 13:31
  • \$\begingroup\$ i added an video for showing my problem \$\endgroup\$
    – brian661
    Commented Jan 3, 2014 at 14:22

0

You must log in to answer this question.

Browse other questions tagged .