- Home /
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 :)
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! :) 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:
http://forum.unity3d.com/threads/100441-Jittery-Object-And-Or-Camera
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.
Thus:
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);
transform.LookAt(TheCarToFollow);
// 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 :-/
You shouldn't be trying to avoid RTF$$anonymous$$- that should be your first plan, not a final recourse!
Have you tried making the camera interpolate to the correct position, ins$$anonymous$$d of moving directly? Is it the entire frame that is jittering, or just the car itself? It seems like there is some kind of bad interaction happening between the car and the camera- are they controlled completely independently, or does the car's movement depend on the camera's position in some way?
@sycla, for sure, on the cam I tried every type of interpolation and smoothing - frustrating! Regarding your second sentence, as you know it can be difficult to absolutely deter$$anonymous$$e that with the eye in these cases (you have to zoom in and out a bit, it sometimes helps in making a deter$$anonymous$$ation) -- my judgement is that possibly BOTH jiggle, but the car in a different/bigger way. Regarding your 3rd sentence, I agree with you completely - but the system is so simple it's fair to say it's certain there is no obvious interaction of the type you describe. I wonder if there is something mysterious and obvious I plain don't know about the order (???) in which say these operations are done network wise, or, who knows? Also note the edit I added ... from the forums
It's definitely possible to do 'true' puppetry in Unity, but you'd be limited by the 15-update-per-second network speed- which creates visible jitter without some kind of interpolation. Putting a rigidbody on it just allows the interpolation to be a little 'smarter' by giving it all the same behaviours it has on the server.
Hi @sycla, in the end it had absolutely nothing to do with any of the topics mentioned. There is (as one would expect) absolutely no requirement whatsoever to have rigidbodies present on network-driven objects, and it makes no difference at all to physics or DR issues whether you do or not. Nor is it the usual Horrific Interleaving Problem one would expect with 3D networking. (Apparently Unity have completely resolved all such issues - God bless them.) In this case it was nothing more than a particular camera angle that would sawtooth because of the discreteness of the object movement under networking. Thanks again for your time!
Answer by Fattie · Jun 09, 2012 at 09:29 AM
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.
Answer by carmine · Oct 05, 2014 at 04:22 PM
I'm having the same issue! Without Lerp there is no jitter, with lerp there is jitter. How did you fix it?