0
\$\begingroup\$

Currently I'm participating in a multiplayer game project as a network developer. Unfortunately, however, I'm facing an interpolation problem which makes game objects look like they are 'jumping/teleporting' sometimes. Images don't look smooth compared to the server even if the client runs at 60 frames per second.

Things about the architecture:

  • Based on client/server model. server sends regular transform updates at every 33 milliseconds (30fps).
  • Client receives and stores position updates in a queue. then, plays them from 1 second behind using interpolation between each update.
  • Before processing the next packet, client calculates the sent time between current and next packet to find out how many milliseconds this interpolation should take. at every frame, it deducts the delta time from the interpolation time. so, if interpolation time reaches a number equal or less than zero, it iterates to the next packet (if the value is less than zero, it means that there is a time fragment. so the client also considers that time fragment for interpolation of the jumped packet at the same frame.)
  • Client doesn't deal with rigidbody; only position and rotation.

I'm using Unity3D's LERP method from the Vector3 class. Using SLERP didn't solve the problem.

Any ideas? Everything looks great on paper.

\$\endgroup\$
2

3 Answers 3

4
\$\begingroup\$

It seems the problem caused by Unity's double typed timestamp which is included in the NetworkInfo packet. Since most of the Unity classes utilize from float instead of double, I was applying typecasting on the timestamp which was leading to loss of data.

After realizing that, I've inserted my own timestamp using Time.time (a float value) to each packet. Now, everything looks fine.

\$\endgroup\$
3
  • \$\begingroup\$ You should mark this as selected answer, to help future visitors. \$\endgroup\$
    – o0'.
    Nov 19, 2013 at 10:06
  • 1
    \$\begingroup\$ Why are you using a floating point timestamp? You would better use an int for this kind of thing. \$\endgroup\$
    – o0'.
    Nov 19, 2013 at 10:06
  • \$\begingroup\$ Because that's how Unity represents time. Time.time is a float value of seconds (using fractions to represent ms) \$\endgroup\$
    – Vasisualiy
    Dec 30, 2014 at 12:31
0
\$\begingroup\$

Linear interpolation should be fine. The trick is to figure out which two states to interpolate between, not the interpolation itself. Maybe this will help? http://gabrielgambetta.com/fpm3.html

I disagree with the other reply, you definitely need interpolation even if you don't lose packets (except if you get exactly one packet per frame with zero lag and zero loss, which is unrealistic)

\$\endgroup\$
-1
\$\begingroup\$

If game objects can get the correct position updatings each frame there's NO need to use interpolation, you just update the position the same in single-player mode.

But packet loss always happens in WLAN, you may need to predict the game object transform in client.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Not quite. In practice you always need some kind of local interpolation/extrapolation to keep the display smooth, even on a well behaved network variances in ping will make everything look very twitchy. \$\endgroup\$ Nov 18, 2013 at 4:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .