Animations on photon cloud

Options
I'm currently trying to program a multiplayer game and i am using the networkrigidbody.cs however i can get all the positions and rotations in sync the problem is the animations aren't networked and local players can only see their animations. I have tried using the OnPhotonSerializeView in the character controller and observing that with the photonview but it still doesn't work.

I used the code from the marco polo tutorial but it doesn't seem to be working for me i'm using the default character controller just ported to C#

[code2=csharp]public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
if(stream.isWriting)
{
ThirdPersonController tpc = GetComponent<ThirdPersonController>();
stream.SendNext((int)tpc._characterState);
syncPosition = transform.position;
stream.Serialize(ref syncPosition);

}
else
{
ThirdPersonController tpc = GetComponent<ThirdPersonController>();
tpc._characterState = (CharacterState)stream.ReceiveNext();
stream.Serialize(ref syncPosition);
transform.position = syncPosition;

syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;

syncStartPosition = transform.position;
syncEndPosition = syncPosition;

}[/code2]

That is the code i have in the character controller

and here is the code i have tried on the networkrigidbody

[code2=csharp]void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
// Send data to server
if (stream.isWriting)
{

ThirdPersonController tpc = GetComponent<ThirdPersonController>();
stream.SendNext((int)tpc._characterState);
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
//Vector3 velocity = Vector3.zero; //rigidbody.velocity;
//Vector3 angularVelocity = Vector3.zero; // rigidbody.angularVelocity;

stream.Serialize(ref pos);
//stream.Serialize(ref velocity);
stream.Serialize(ref rot);
//stream.Serialize(ref angularVelocity);
}
// Read data from remote client
else
{

ThirdPersonController tpc = GetComponent<ThirdPersonController>();
tpc._characterState = (CharacterState)stream.ReceiveNext();
Vector3 pos = Vector3.zero;
Vector3 velocity = Vector3.zero;
Quaternion rot = Quaternion.identity;
Vector3 angularVelocity = Vector3.zero;
stream.Serialize(ref pos);
//stream.Serialize(ref velocity);
stream.Serialize(ref rot);
//stream.Serialize(ref angularVelocity);

// Shift the buffer sideways, deleting state 20
for (int i=m_BufferedState.Length-1;i>=1;i--)
{
m_BufferedState = m_BufferedState[i-1];
}

// Record current state in slot 0
State state;
state.timestamp = info.timestamp;
state.pos = pos;
state.velocity = velocity;
state.rot = rot;
state.angularVelocity = angularVelocity;
m_BufferedState[0] = state;

// Update used slot count, however never exceed the buffer size
// Slots aren't actually freed so this just makes sure the buffer is
// filled up and that uninitalized slots aren't used.
m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);

// Check if states are in order, if it is inconsistent you could reshuffel or
// drop the out-of-order state. Nothing is done here
for (int i=0;i<m_TimestampCount-1;i++)
{
if (m_BufferedState.timestamp < m_BufferedState[i+1].timestamp)
Debug.Log("State inconsistent");
}
}
}[/code2]

Any ideas why this isn't working?

Comments

  • Hi,
    http://www.youtube.com/watch?v=4AZADiKD2sE
    Check this out ! I had the same problem and this video helped me to solve it ! Hope this helps ! :D

    Regards,
    Razor.
  • Thank you for the help, however as mine doesn't use an animator component and the models have the animations attached to them i can't figure out how to modify it to match my game.
  • Anyone know how i can fix it without changing my animation system?
  • Tobias
    Options
    You can't really sync the animation itself. It blends several animations and must be times very precisely.
    Even if you'd send all the states, frames and animations per character, the variable lag will make it look choppy and inconsistent.
    So, the solution is almost always to have some script analyze what the remote players do with their characters and then apply the fitting animations locally. Lets say your character was standing and begins to move with the next update, your script has to run the fitting animations.
    I don't really have a good example for this. I rarely work with animations in Unity, aside from basics and never used Mechanim (e.g.). Maybe the Worker Demo is a blueprint you can use (it's in the PUN package). It animates the worker according to incoming info.