NetworkTransform - interpolation?

I’ve got NetworkTransform working between server and client. Setting the Network Send Rate to 1 sec does exactly that, my objects position gets updated once per sec on the client. Oddly, you can’t set this number to a smaller value on the editor, but I can force it from script to e.g. 1/30, in which case I get more updates - and more data traffic.

Question: How do I enable position and rotation interpolation with Transform Sync Mode == Sync Transform?

As a side note, releasing a new feature without proper documentation is not the right way to do it. Thanks.

You could use the editor to put it to 1/29 of a second, thats the fastest you can get via editor.
Have you tried the interpolate movement factor and rotation factor?

Thanks for reply - I believe the send interval is in seconds, not in fraction of seconds, at least the documentation says “transform state updates are send at most once every sendInterval seconds.” Putting it to 29 would mean an update every 29 seconds, which makes little sense.

I did try to change the factors, no luck there. The documentation is also somewhat cryptic: “The larger this number is, the faster the object will interpolate to the target position.”

Looking in debugger, the target position for NetworkTransfor is 0,0,0.

Well, if you try it you will see that it is “updates per second” and the tooltip says the same, so 29 is 1/29th of a second.

Interpolation works for me. You could make a simple connection, a cube with a fixed movement on the server and 1 full second update interval.
Start the build as a server, the editor as a client. You can use the editor for changing Interpolation on the fly and see which value is best for you. I have rotational at about 30 (I don’t know what, maybe degrees per second…) and position at 0.5 (I guess a lerp between a and b with 0.5 as a mix)

Thanks, it seems the documentation is just a bit fuzzy. I still can’t get the interpolation to work however.

Unity: Perhaps wikipediafy the documentation so we can easily clarify it when necessary. :slight_smile:

There was briefly a comment section in the docs if I remember correctly. The community usually has all the details that the docs are lacking. It wasn’t used enough though, which may contribute to why that feature is gone.

Regarding the interpolation, you will find that it doesn’t work on the ‘transform’ interpolation method. I’m not sure if this is a bug or by design. Docs don’t tell you so I’ve been assuming bug, but can’t confirm that. It would be pretty nice to have it work for transform type interpolation too.

If someone can explain how to let ANY interpolation work on the network transform, ill get you a cookie :slight_smile:
Ive tried everything… But it looks like all the syncs modes are just some position sending…

This is from another thread:

Thanks guys. I’m implementing a simple interpolation code of my own.

Yes there’s no built-in transform interpolation atm. I don’t think its a bug, I think it’s by design, and they just made it visible for all cases and not just rigidbody, even though it only works for rigidbody. But like I said in that other thread, if its a mistake they’ll either hide that option if you select transform, or they’ll just add interpolation to the transform too. I don’t see why not, its fairly easy to do. :slight_smile:

Does NetworkTransform perform any prediction to compensate for latency? Or will the object always be like 100 ms behind where it really is locally? (Assuming 100 ms latency)

This kind of sucks. It will only update the rotation when I move. It seems like rolling your own is the only decent option.

Here’s a good tutorial that was mentioned:

Here’s some unoptimised sample code sending every fixed update:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class Player_Sync_Pos : NetworkBehaviour {

        [Header("Options")]
        public float smoothSpeed = 10f;

        [SyncVar]
        private Vector3 mostRecentPos;
        private Vector3 prevPos;

        void FixedUpdate()
        {
                if (isLocalPlayer)
                {
                        // If moved, send my data to server
                        if (prevPos != transform.position)
                        {
                                // Send position to server (function runs server-side)
                                CmdSendDataToServer(transform.position);
                                prevPos = transform.position;
                        }
                }
                else
                {
                        // Apply position to other players (mostRecentPos read from Server vis SyncVar)
                        transform.position = Vector3.Lerp(transform.position, mostRecentPos, smoothSpeed * Time.deltaTime);
                }
        }

        [Command]
        void CmdSendDataToServer(Vector3 pos)
        {
                mostRecentPos = pos;
        }

}

If it’s really the case that interpolateMovement does absolutely nothing if transformSyncMode has a certain value, and it’s not a bug but either “by design” or something that has been deliberately left for future development, how come this isn’t mentioned anywhere in the documentation? Seems odd…

Thanks to Stardog, though. You got me in the right direction! :slight_smile:

I could simplify it a lot, as my transforms are only moved on the server, and added rotation as well. Also added an “snap distance” where it will move immediately, in case it gets out of sync, and an initialisation of the “most recent” to the current values in Awake, to avoid a snap to (0, 0, 0) in the first frame.

I think you don’t need the “prevPos”, as you can just check against the value of the SyncVar.

Unity devs… when syncing non-physics based objects… is when not having interpolation is the most visible. And that’s the case where you don’t support interpolation !?

Yes afaik interpolation doesn’t apply to transforms. You need to put a rigidbody on so it works. But you can write your own interpolation.

Yeah i have to say - this bug or feature whatever you might call it is pretty sad - how long us UNet out already?
Unity Devs, do you know how many combined hours people have wasted trying to get interpolation to work?

Hide the interpolation for transform and explain why it’s not supported or better: just fix it.
NetworkTransform is probably one of the most important scripts for networked games.

By the way: Interpolation doesn’t work for me when i have a kinematic rigidbody attached, only when it’s not kinematic.

2 Likes

There is a weird edge case where setting the parameters on your PlayerPrefab to conventional kinematic options and thereafter setting the Network Send Rate to zero will receive very smooth updates on the host machine but the host machine itself does not send movement updates to clients. Weird.

I don’t think anyone mentioned character controllers so I’ll post for posterity, since this is still easy to find when searching for the answers.

Yes, the Sync Transform mode does not do any interpolation.

No, you do not have to use a rigidbody, though you can. The alternative is to use a character controller and Move/SimpleMove functions with Sync Character Controller. Like other parts of Unity, such as collisions, you shouldn’t just manipulate the transform for movement.

Yep, the documentation doesn’t mention this and the official multiplayer tutorial even leads you to use the transform method. I wasted time too :face_with_spiral_eyes:

1 Like

Check the source code of a demo. It includes Snapshot Interpolation Technique. Smooth movement on 160+ ms latency. There is also Camera rotation sync if you’d like to synchronize the player’s model head.
https://wobesdev.wordpress.com/2016/09/09/networking-on-unity5/