[Multiplayer] Smooth movement.

I try to smooth movement by Vector3.Lerp. But I have some problems with this…
Characters goes to position (0,0,0), weird…

This is my code:

#pragma strict

    var truePosition : Vector3;
    var trueRot : Quaternion;

function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) { 
    if (stream.isWriting) {
         var Position : Vector3 = transform.position;
         var Rot : Quaternion = transform.rotation;
        stream.Serialize (Position);
        stream.Serialize (Rot);
    } else {
        stream.Serialize (Position);
        stream.Serialize (Rot);
        truePosition=Position;
        trueRot=Rot;
    }
 
}

function Update()
{
if(!networkView.isMine){
transform.position = Vector3.Lerp(transform.position, truePosition, Time.deltaTime * 1);
transform.rotation = Quaternion.Lerp(transform.rotation, trueRot, Time.deltaTime * 1);
}
}

I am not sure exactly what is wrong with this code initially looking at it as I haven’t done this in JavaScript. In C# you would want to pass the reference to your object into the serialize method. Have you tried to log out what truePosition is at the end of the serialize?

Make sure to have the Network View observing the script implementing OnSerializeNetworkView. Check under the “Choosing data to send” section of the documentation for more info here: http://docs.unity3d.com/Manual/class-NetworkView.html

1 Like