problem with sliding/scooting character

Hi:

I am using the Goober character from Unity's CharacterAnimation
demo in a test of my own. I do a Network.Instantiate of the character
and have it show up in two different windows. And when I press the
arrow keys in the window that "owns" the character, both copies
move around the scene. In the window that owns the character, it
is fully animated as desired. However, in the other window, the
character merely scoots across the terrain rather than "walking",
i.e. rather than being animated. I have looked at the CarRacing
demo in the Networking sample project because I thought it might
give me some hints on how to fix the problem. But so far I am
missing something from all the demos I have examined. Helpful hints
would be greatly appreciated.

Thanks.
--ralph

You probably need to specifically sync the animation of the character. In the ThirdPerson scene in the example project the animation state of the character is synched over the network when it changes. Check out the ThirdPersonSimpleAnimation.js script and NetworkSyncAnimation.cs.

Thanks for the reply. This did help me solve the problem
with that character. I now have a similar problem with
another character that I had hoped I could solve in the
same way. Ah well, perhaps I will post again if I learn enough
to ask a reasonable question.
Thanks again.
--ralph

You know, I am also having the same problem.

The character on my project is "scooting" too. Specifically, it is looping the "idle" animation.

I went through the Network sample, but for some reason that file performs the same way.

When I build the Network sample the Lerps "walk" cycle is looping on the networked machine. It doesn't matter if I move the character or not. No "idle" or any of the other animations seem to be working with the sample.

I wonder if I am doing something wrong.

Basically I build the sample "binary standalone" and test it between a macbook pro and a powerbook g4.

All controls, chat, etc work properly. But the animation does not sync on the 3rd person sample.

Does the Network sample work correctly for anyone else?

I forgot to mention that the TPS-Auth sample also has the same problem.

The Lerpz "walk cycle" is looping. None of the other animations work on networked machines.

It almost seems that this bit of code does not work at all.

if (stream.isWriting)
        {
            char ani = (char)currentAnimation;
            stream.Serialize(ref ani);
        }

What I do is serialize a state variable which I then use to decide which animation to play.

That sounds like an interesting technique. . .

I'm pretty slow when it comes to programming, could you please walk me through your process?

I'm using an enum to specify the state. Not sure how enums are used in javascript - if that is the language you use, but here goes:

We first define the enum which specifies the states the character can be in and set it to idle as default:

enum PlayerState{ Idle, Run, Aim };
PlayerState state = PlayerState.Idle;

Now when player input prompts the character to move, we change the player state accordingly:

state = PlayerState.Run;

This is used in our update to set the animation:

void Update()
{
    Vector3 pos;

    switch( state )
    {
        case PlayerState.Idle:
            animation.CrossFade( "idle" );
        break;
        case PlayerState.Run:
            animation.CrossFade( "run" );
        break;
        case PlayerState.Aim:
            animation.CrossFade( "aim" );
        break;
    }
}

Finally we make sure the state is synced. However enums do not serialize so new need to convert to int beforehand - like so:

int convertedState;
if( bitStream.isWriting )
{
    convertedState = ( int )state;
    bitStream.Serialize( ref convertedState );
}
else
{
    bitStream.Serialize( ref convertedState );
    state = ( PlayerState )networkedState;
}

Wow thank you. That really helps me a little further. I sort of combined your code to the "NetworkSyncAnimation.cs" and "ThirdPersonSimpleAnimation.js" scripts on the Lerps network demo.

I'm still getting sliding characters when I network a powerbook with a macbook.

Clearly I am doing something wrong here. The network demo still has sliding characters on my machines.

Would it be possible to provide me a little more guidance on this?

Everything else seems to network perfectly. Animation is my only problem.

using UnityEngine;
using System.Collections;
using System;

public class NetworkSyncAnimation : MonoBehaviour {

    public enum PlayerState 
    {
        idle = 0,
        walk,
        run,
        jump
    }

    public PlayerState state = PlayerState.idle;

    // Update is called once per frame
    void Update () {
        Vector3 pos;
        switch( state )
        {
            case PlayerState.idle: animation.CrossFade( "idle" );
            break;
            case PlayerState.walk: animation.CrossFade( "walk" );
            break;
            case PlayerState.run: animation.CrossFade( "run" );
            break;
            case PlayerState.jump: animation.CrossFade( "jump" );
            break;
            }       
        }

    // Network Stuff
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
        {
            int convertedState;
            if(stream.isWriting )
            {
                convertedState = ( int )state;
                stream.Serialize( ref convertedState );
                }
                else
                {
                convertedState = ( int )0;
                stream.Serialize( ref convertedState );
                state = ( PlayerState )convertedState;

                }
        }
}

Here's what's in the "ThirdPersonSimpleAnimation" script now

        else if (currentSpeed > 0.1)
    {
        animation.CrossFade("walk");
        animation.Blend("jumpland", 0);
        SendMessage("state", "PlayerState.walk");
    }

Ok I am still stumped here.

Again, the lerps character in the network demo seems to loop the walk cycle on all networked machines (powerbook and macbook pro).

Did this network demo actually work for anyone else?

Thanks in advance for any help or insight.

The idea is that you completely control animation by setting the state and thus only change the animation in the update which responds to the current state. Therefore I do not get why you're modifying the animation in your "ThirdPersonSimpleAnimation" script - this seems to counter the idea. However the snippet isn't descriptive enough to let me conclude this.

Sorry for the late reply, I'm falling behind on other projects...

Your point does make sense to me. I guess what I am trying to do is make sense on why the the Lerps character in the Third Person Networking sample (from the resources section on the unity website) does not seem to play the "walk, run, jump, etc" animations properly on networked machines.

I tested this on different machines and on different networks and I always seem to get the same result (looping walk cycle only, no other animations).

Looking through the code in the sample, it seemed to me that the "ThirdPersonSimpleAnimation.js: contains this:

// Fade in run
    if (currentSpeed > marioController.walkSpeed)
    {
        animation.CrossFade("run");
        // We fade out jumpland quick otherwise we get sliding feet
        animation.Blend("jumpland", 0);
        SendMessage("SyncAnimation", "run");
    }

My thought was that this:

SendMessage("SyncAnimation", "run");

tells the "NetworkSyncAnimation.cs" script to change the animation state here:

public AniStates currentAnimation = AniStates.idle;
    public AniStates lastAnimation = AniStates.idle;

    public void SyncAnimation(String animationValue)
    {
        currentAnimation = (AniStates)Enum.Parse(typeof(AniStates), animationValue);
    }

So basically what I did was substitute the sample code with the code you posted (thank you for this by the way)

So I guess my main question was:

1) Does the network sample work correctly for anyone else?
2) If so, what exactly are you doing to make it work properly?

And my new question is:

1)Clearly I am not using your code properly. Are you telling me that the "ThirdPersonSimpleAnimation.js" is actually not necessary to make the network animations work properly?

Thank you again for your help on this.