Search Unity

[Multiplayer] Smooth movement.

Discussion in 'Multiplayer' started by MintFork, Feb 22, 2015.

  1. MintFork

    MintFork

    Joined:
    Feb 22, 2015
    Posts:
    17
    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:
    Code (JavaScript):
    1.  
    2. #pragma strict
    3.  
    4.     var truePosition : Vector3;
    5.     var trueRot : Quaternion;
    6.  
    7. function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) {
    8.     if (stream.isWriting) {
    9.          var Position : Vector3 = transform.position;
    10.          var Rot : Quaternion = transform.rotation;
    11.         stream.Serialize (Position);
    12.         stream.Serialize (Rot);
    13.     } else {
    14.         stream.Serialize (Position);
    15.         stream.Serialize (Rot);
    16.         truePosition=Position;
    17.         trueRot=Rot;
    18.     }
    19.  
    20. }
    21.  
    22. function Update()
    23. {
    24. if(!networkView.isMine){
    25. transform.position = Vector3.Lerp(transform.position, truePosition, Time.deltaTime * 1);
    26. transform.rotation = Quaternion.Lerp(transform.rotation, trueRot, Time.deltaTime * 1);
    27. }
    28. }
    29.  
     
    Last edited: Feb 22, 2015
  2. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    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?
     
  3. KyleOlsen

    KyleOlsen

    Joined:
    Apr 3, 2012
    Posts:
    237
    Brent_Farris likes this.
  4. adi7b9

    adi7b9

    Joined:
    Feb 22, 2015
    Posts:
    181