Multiplayer: jitter caused by camera? by smoothing?

Later: for anyone who’s been following this question or has a similar problem:

I discovered that the camera jiggle was caused by: camera jiggle :slight_smile:

Like I said, the camera would (mysteriously) not jiggle if you locked on the vehicle; it would jiggle in an odd way if you smoothed the camera, interpolated, in any way .

To me, this seemed to suggest some unusual interaction of the networking system - perhaps the rigidbodies, the DR or interpolation or one of those hellish complicated problems involving interweaving of rendering/physics/networking, or some issue regarding how physics is handled in network-puppeted objects.

Fortunately - it had utterly nothing to do with this! :slight_smile: Yay, Unity - Unity’s interweaving seems to be perfect.

The only problem was that essentially you have to smooth the camera against a smoothed tracking point. If you smooth (whatever technique used) the camera against the vehicle, which is in fact moving in steps (since it’s pupated by the network), the camera motion from certain angles (naturally I was using such an angle) will sawtooth (a curved ascender / flat descender sawtooth).

That’s all the problem was.

once again if you are seeing this problem – mysterious jitter on a camera at certain angles when MP – you will likely, like me, assume it is the typical horrific networking-physics-interweaving problem. In fact, Unity seems to have astoundingly solved all such problems (God bless them, the price should be higher than it is) - and you’re just seeing a “completely correct” sawtooth effect on the camera (nothing to do with the vehicle)

Solutions if you are in this situation: set the networking to a low speed (1 hz) and you will much more clearly see what the hell is happening. Likely this will solve the problem straight away.

I hope this helps someone in the future !!!

I’ve been experimenting with Unity’s MP system and found an unusual effect:

I set up a trivial server-client on two iPads. There is a surface, and a simple car-looking vehicle.

The server can drive the car around. The client shows the car driving around.

It can easily run at 30+ FPS. I implanted NO interpolation or DR - simple raw MP.

Now, on the client side, if the camera is simply fixed (say, overhead, looking at the car driving around), the motion is perfectly smooth on the client. Works beautifully.

(Again - there is NO interpolation/DR at this stage. But as you’d expect, since the system is so simple and it’s running at a very fast rate, there is no jitter at all - perfectly smooth. As smooth as using your wireless mouse.)

HOWEVER, if I make the camera follow the car (again this is on the client), a jitter is introduced. It’s hard to tell but it seems to be a “back one” jitter (the car appears in position ABACBDCEDFE … and so on, perhaps).

I have tried smoothing out the camera tremendously, it just doesn’t seem to help.

Experienced developers, is there something I am missing? Something odd perhaps about the order of operations of updating the car position / camera position? (I tried moving the camera used on both physics/frames … no difference.)

Once again if the camera is fixed the apparent movement of the car is perfectly smooth. However, making the camera follow the car (tried many techniques), a severe jitter is introduced to the car.

Is there something obvious about Unity, Unity MP, I don’t know about, anything I’m missing?

LATER: the only other mention I have found regarding this is:

Note that Ferros’s solution seemed to be that: essentially, automatic observation is useless, and you just have to serialise the values (presumably so you can exactly control the events in time …) Annoying and not really a fullly-understood solution!

LATER - in fact Ferro’s solution did not solve the problem in my case. I can still exhibit the jitter. Pretty annoying!

LATER Hi @Sycla … right, I have totally abandoned automatic observation. (It’s a shame the mechanism / actions ordering is not explained clearly by Unity - if something’s a problem in a system, it’s good to understand exactly why.) {In any event, it appears to be unrelated to the problem, as I am testing it both ways with the same results. But it’s one factor out of the equation.}

Correct, I am currently serialising the vehicle transform. The camera position is handled purely locally on the remote machine. To repeat the camera position is not at all sent in any way. The remote machine alone sets the camera position. I still see the same strange problem. To wit:

If I use any camera movement, that simply locks on to the vehicle, then, there is no jitter - smooth as silk.

If I use any camera movement that tries to smooth the movement (any typical camera strategy like “smooth follow” “delayed panning” or the like), strangely that results in the jitter.


GoalCameraPosition = TheCarToFollow.position;
GoalCameraPosition += TheCarToFollow.forward * -6.1;
GoalCameraPosition.y = 2.45;	// fixed height, let's say, or you can make it a fixed height above
                                                    // TheCarToFollow.position, no difference in the jitter problem

// the following line works ok .. no jitters !!
transform.position = GoalCameraPosition;

// however, the following line results in jitters !!
//transform.position = Vector3.Lerp(transform.position, GoalCameraPosition, Time.deltaTime*10);


// the following line can can seemingly to some extent stop the camera jiggling; in other words
// the background will no longer jiggle.  however, in this case the car still jiggles.
// transform.rotation = Quaternion.Euler (0, transform.eulerAngles.y, 0);	

I run that code in LateUpdate - but it doesn’t make much diff where it runs.

To recap, in answer to your question of yesterday, I am somewhat sure it is MORE THE CAMERA that jitters. Watching on the editor screen as it’s running, you can actually see the camera frustum jiggling. Whereas you can see the car moving around, seemingly perfectly smoothly (of course the editor, who knows the relationship to the rendered environment - but that’s what I see.)

To repeat, making the camera simply LOCKED ON TO the vehicle (say a fixed 3 meters back, 1 meter up) … results in no jitter for the car and no jitter for the background.

However, bizarrely, simply adding the Lerp results in jitter for both the car, and the background. As best as I can tell, in fact it’s the camera that is jittering, possibly (but not certainly) it’s not the car that is jittering. In that situation (jitter caused by the smoothing), if you do add that final line of code (which simply stops the camera yawing or pitching) it eliminates the jitter of the background, but the car jitters.

To be clear, if the identical code is run on the server (i.e., where the car “actually” is and the car can be moved around), there is no jitter at all, everything is as flawless as unity usually is.

Once again, the mystery is: a difference between the “fixed” approach, which works with no jiggle, and any sort of smoothed approach (such as the trivial Lerp shown) which results in the jitter. (Apparently, but not for certain, the jitter is in the camera - but then, this must, in some sense, be caused by some sort of jitter or behaviour, perhaps an inter-frame jitter, or something, in the vehicle, as the pos of the cam of course just comes from the vehicle).

Go figure :-/

Solution: if you are in this situation: set the networking to a low speed (1 hz) and you will clearly see what the hell is happening.

In this specific case it was nothing more than the camera sawtoothing !!

There was no connection to automatic observation issues, interleaving, rigidbody networking woes, or anything else you’d naturally assume is the problem when you get jitter w/ networking.

I’m having the same issue! Without Lerp there is no jitter, with lerp there is jitter. How did you fix it?