- Home /
Question by
shlomisaad · May 10, 2015 at 06:47 PM ·
c#networkingphoton
entity interpolation problems
I read a lot about entity interpolation but I failed to implement it correctly. I am using Photon and that is the code:
void OnPhotonSarialezedView(PhotonStream stream, PhotonMessageInfo messageInfo)
{
if (stream.isWriting)
{
State state;
state.position = rigidBody.position;
state.timeStamp = (float)messageInfo.timestamp;
stream.SendNext(state);
}
else
{
if(states.Count<=20)
states.Add((State)stream.ReceiveNext());
if(states.Count >= 20)
{
var startPos = states[0].position;
var endPos = states[1].position;
var timeInterval = states[1].timeStamp - states[0].timeStamp;
states.RemoveAt(0);
gameObject.transform.position = Vector2.Lerp(startPos, endPos, timeInterval);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613195256im_/https://answers.unity.com/themes/thub/images/avi.jpg)