So I’m working on a networked multiplayer game where all the players control a single player vehicle.
The entire setup is like this: The server starts and loads the scene, the clients connect to the server and loads the same scene. The game objects get different components based on whether they’re on the client or the server. For instance, the server object gets mesh collider and rigidbody components, where as the client object doesn’t. The game clients are just for displaying a top down “radar” view and controls, so I thought it didn’t need to do any physics calculations. The server shows a first person view from the player vehicle. Each object has a netview and the client objects get positional updates from the server objects.
The problem is on the client. I have a script that makes the top down camera follow the player vehicle. The camera jitters as soon as the player vehicle hits an object. If I stop the player vehicle the jittering stops, but starts again if I move the player vehicle.
I’m sure it’s the camera because I’ve tested it without the camera follow script and everything is smooth then.
Here is the camera code:
using UnityEngine;
using System.Collections;
public class CamFollow : MonoBehaviour {
void LateUpdate () {
GameObject playerVehicle = GameObject.Find("Player Vehicle");
float xAxis = playerVehicle.transform.position.x;
float zAxis = playerVehicle.transform.position.z;
transform.position = new Vector3(xAxis,2.0f,zAxis);
transform.rotation = Quaternion.AngleAxis(90, Vector3.right);
}
}
I’ve tried many things like turning interpolation on the rigidbodies on, but this has no effect.
Not related to your problem: Do not do a GameObject.Find every frame, as that is a time-consuming process. you should be caching the result of that into a variable.
You should do similar things with the transform.position/rotation lines. On awake, cache the ‘transform’ value into a variable, and use that instead.
Related to your problem: This is usually due to different scripts updating at different stages each frame, as it’s ‘random’ in a sense as to which one runs first. Look for another script that might be moving/rotating your camera, be it in the LateUpdate, or inside Update.
Hey cerebrate, thanks for replying. Ok, I’ve changed it.
This is literally the only script that moves the camera.
Also, I’ve noticed another strange thing that may or may not be related. On the client camera, when it object gets to the edge of the field of view the object will just dissappear instead of moving off screen.
Anybody? I’ve tried everything I could think of, interpolate the server rigidbodies, puting rigidbodies on the client objects, LateUpdate(), FixedUpdate(), regular Update(), etc. There has to be a solution for this.
i´ve a similar problem with a torso rotation;) have you tried to use the NetworkInterpolatedTransform.cs from the network tutorial?
is a network view attached to your cam? since i don´t have one attached to my cam i don´t have any trouble with “jitter-cams”^^
I have not tried that script. I haven’t even gone through the network tutorial. Just going by the reference and scripting manuals. I’ll try that when I get home.
There’s no network view attached to the cam, but the player vehicle object has a network view, and the script makes the camera follow it.
In my game all the clients take control of different aspects of the player vehicle. On the server the camera shows a first person view from the vehicle, and the clients show a top down view on the vehicle.
Could this problem be because I’m sorta mixing transforms with physics?
I changed the synchronization type to unreliable and write a script for sending and receiving the objects transform data instead of having the network view just observe the objects transform.
I was/am having exactly the same problem as you. You might like to read my post here,
Just as you say, it seems to be some aspect of the camera, the camera interaction. In my case, if I simply hold the camera in a static position, the movement is perfect with no jitters. But if the camera follows, in any way, jitter happens.
Just like you, I tried every possibility of when to move/draw/interpolate etc. I assumed the problem was what cerebrate mentioned, but it does not seem to be the case, annoyingly.
The solution you suggest seems to be that “transform observation is useless and doesn’t work.”
If that is the case … what a sad situation!
I also find it strange that … every single person who throws together a two-line demonstration of multiplayer, should immediately see this problem. It should be the overwhelming thing discussed about Unity, everywhere! But the problem is barely mentioned.
So the whole thing is quite mysterious.
Did you happen to stumble on to any more information in the couple months since then?
Hey, guys. Sorry for necroing, but I`m having the exact problem in my game and indeed, it seems like it should be mentioned more since it is so obvious, when you get to such a case. However, a game very rarely needs a use case like that. For me it’s spectator mode that switches the camera to other players and instantly there is jitter and objects seem desynced and it’s all just terrible. I have tried literally everything and also made a post here: Cinemachine following networked objects (jitter)
My specific case: my network view interpolates between the last few network snapshot states received by network object and a camera follows this network view with just setting the transform position to objects’ with an offset - this so far has yielded best results, however still far from playable. I do not know what to do.