Anyhelp appreciated this one is driving me up the pole. I have a smooth camera following a skate boarder (rigid body, wheel colliders etc). Now if I lock the camera to the skater the camera is smooth, no jitter. But when I add the smoothed follow camera it jitter pretty badly. This is completely the opposite behavior that I would expect! Even worse I cannot stop it. Here is my camera code: Code (csharp): float camlerpspeed = 2.0f; camlerpspeed *= Time.smoothDeltaTime; cameraPosition = playerTransform.position; cameraPosition -= (playerTransform.forward * (cameraZOffset * 0.1f)); cameraPosition.y = playerTransform.position.y + (cameraHeight * 0.3f); this.transform.position = Vector3.Lerp(this.transform.position, cameraPosition, camlerpspeed); this.transform.LookAt(playerTransform.position); I've tried storing the players last position adding them and dividing by two and lerping to that instead (from another thread) , with no luck. ive tried messing with ordering by moving my camera code to LateUpdate etc. The only thing that lessens the effect is reducing the camelerpSpeed variable but then the camera trails way too far behind the player! Any idea what is causing this jitter ? Thanks
I encountered same problems when my camera was a child node of an object it was following. You can also put this code in LateUpdate(). Maybe this will help...
Thanks for your reply , The camera has no parent nodes, I tried LateUpdate() as well with no observable difference.
Ok if i set the lerp to 1.0f it becomes a static camera and is completely smooth. The lower I set the value the more it jitters. I still cant understand why this would be happening,
I am having a very similar issue. If I try to use any sort lag/smoothing calc, the camera is jerky. Anyone have any ideas? -Jeff Weber
My progress so far is that it IS the physics system smoothing the physics system is def helping by reducing the value if Fixed timestamp http://unity3d.com/support/documentation/Components/class-TimeManager.html This isnt ideal as im developing for iPhone so im looking into smoothing the cameras look at point as well.
You can try camera script from Unity's CarTutorial. If it will jitter then problem is somewhere else. But I have seen camera jitter bug in many samples and it looks like problem is more complex. Ah, I remembered one thing. There is Interpolate property in Rigidbody component. If I am correct setting it to Interpolate or Extrapolate will smooth object movements between different updates (not only fixed updates).
Do you move the skater with physics forces? If yes this could be the problem, as referencing a body that is beign forced by physics by its transform will result in this. I had this problem on my player look script for first person, I solved in one way, by adding a dummy object which is moved by my mouse script which only work out on the transform rotation of the camera and the dummy object that is child of the player. Then and only then I apply the force to the rigidbody that is dependant to the dummy object direction, all this with Interpolation on and I get smooth movement with and without v-sync. In your case this would be a little more complicated as is in third person for what I understand and you need to work out some more on it.
I bet you that the issue is that FixedUpdate is not running consistently every frame. In other words, for each frame, your skater goes from: (1,0,0) (1.2,0,0) (1.2,0,0) (1.4,0,0) (1.4,0,0) an so on. So your camera (which runs every frame), moves closer to your skater every frame, which is staying still for half the frames. I might move the camera code to FixedUpdate rather than LateUpdate and see what happens. You may have to adjust the script execution order so that the camera script happens after "default time".
I'm experiencing this issue as well and I couldn't find a solution that I understand in this thread. Could anyone give me a clear explanation on how to fix this issue?
It seems to be linked to what you are tracking with the camera as to when to update the position. LateUpdate works well for most systems but I found if you are tracking physics objects which are updated in FixedUpdate then you also want to update you camera positions in the FixedUpdate function.
Good explanation... Helped me. What worked for me is, if the object I am following is not physics based object, camera goes into LateUpdate(). If the object I am following IS physics based, then the camera goes into FixedUpdate().
For anybody searching for answer this is it. You camera has to be in same update as the object you are following. So when player uses physics and updates in FixedUpdate() put your camera movement code into FixedUpdate() as well
I have tested this, one thing to note is that (as it seems), the smooth results may only be visible in a build. And another thing I noticed is that movement seems to have a slight pull/wobble at times (if in fixed update), I'm assuming it could be down to frame rate (not slow but fast frame rate between 60 and over).. Not tested but capping frame rate may remove the pulling/wobble effect.
I had a similar problem that get fixed by using FixedUpdate(). thanks ! For the record, here my story : I had a player that uses physics and the camera position was tie to the player. Everything was fine until I tried to move other objects in the same time I move my player. The other objects seems to be always going back and forth and they are chasing the player. I just move the code in FixedUpdate to fix it.
One way that I found worked well was to, rather than controlling the camera directly, control a gameobject with the camera as a child, on which is a rigidbody with interpolation enabled. As well as this, I enabled extrapolate on my character. This might work for you.
So is the bottom line of all this that the physics system just doesn't work well with Kinematic objects? If you want your game to look professional, you either have to make every object in the game including the camera update in FixedUpdate, or else you have to do everything 100% kinematically?
I have only noticed an issue with the camera and move it to fixed update. If your objects are jittering then turn on interpolation on the rigidbody.
I mean even though the projectile is rotated correctly, it shoots off in an arbitrary direction, instead of the new direction I just applied to it. (My projectiles use object pooling, and there are a lot of them alive at once, so I think we might be seeing old velocities because the physics update is timing out or something.)
Never seen that before. How and where are you setting the velocities? Again. How and where are you setting the velocities?
In the projectile: Code (CSharp): void OnEnable () { rb.velocity = new Vector3(0f,0f,0f); rb.angularVelocity = new Vector3(0f,0f,0f); lifetimeSpent = 0.0f; } //void LateUpdate(){ //Vector3 p = transform.position; //p.y = 0f; //transform.position = p; //} In the shooter: Code (CSharp): var obj = prefab.Get<Projectile>(); if(obj != null){ obj.transform.position = (turret.position + turret.forward) - (turret.forward * timeSinceLastShot * bulletSpeed); obj.transform.rotation = turret.rotation; obj.gameObject.SetActive(true); obj.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero; obj.gameObject.GetComponent<Rigidbody>().AddForce(turret.forward * bulletSpeed, ForceMode.VelocityChange); obj.gameObject.transform.parent = playerShotHolder; } Edit: Can't remember why I put the LateUpdate stuff in there since I also locked the Y axis on the rigidbody. Commented that out. The problem's still there, but I noticed I can't seem to take screenshots of it. I'm begining to suspect it might be an optical illusion caused by screen tearing/monitor refresh issues. When I take a screenshot, the shots look perfectly placed. When I'm playing the game they seem to split into two overlapping streams if I move diagonally.
If vsync is enabled try disabling it. If its disabled enable it. Its enabled by default, usually vsync fixes tearing issues. But this will allow you to see if it is the problem. Your code looks fine so I don't see why it would do that.
vsync had no effect. I managed to take a screenshot of it. I think I had trouble capturing it before because it doesn't happen every single shot. This is a constant stream of projectiles moving pretty quickly.
Okay after digging deeper I think I've figured out the problem. My time between shots was .01f. By increasing it to 0.0625f I managed to get the problem to be invisible, but now my ship doesn't fire as many shots at a time which is less than ideal. I think the cause is something to do with Update being out of step with the physics system, resulting in shots being fired even though the previous shot still hasn't moved yet. This is why it's only visible when moving diagonally (player ship moved on Update but bullet moves on FixedUpdate) or when quickly turning the turret (turret rotates on update but previous shot moves on FixedUpdate) So I ask again, is there any way to fix this, other than moving everything in my entire game to FixedUpdate?
Okay, I went into Edit > Project Settings > Time and changed the Fixed Timestep from 0.02 to 0.01, and changed my player ship's fire rate to 0.02f. I figured if the timestep is twice as fast as the script is pulling the trigger, every bullet must have at least one FixedUpdate. I also added a second bullet, which is something I was going to eventually do anyway, given the twin-barrel design of the ship's turret. This makes up for the fact that I'm firing bullets half as frequently in terms of rebalancing the whole game's damage values. The result is mostly okay. There's some visible inconsistency in the spacing between the bullets. I guess this is due to the small amount of time that has passed between the last physics update and the current Update. There might be a way to mathematically correct for this, but I don't know what it is.
@WarpZone We should move this to its own thread, we have hijacked this old thread. So please start a new thread and @ me so I can respond.
Diversion continued in this thread. Because I know from past experience, Google will send people interested in this subject here, not to the Continuation. Google's stupid like that. Gotta cross-reference the entire internet as you go, otherwise it's unreadable by people living in The Future.
Since fixedUpdate doesn't always run at the same rate, you should multiply your movement vectors by Time.deltaTime. This worked for me.
I am using the cinemachine camera for my follow but it still does the same thing. I fixed the jitter by putting the update mode in the cinemachine brain to fixed and the interpolate to interpolate in the rigid body
This totally worked for me. Making sure both were using FixedUpdate instead of one using LateUpdate and one using FixedUpdate. Thank you!
This... doesn't make any sense. The GPU isn't involved in physics calculations and a high framerate does not impact physics either. Physics runs on a fixed timestep that is not impacted by the in-game framerate. No amount of movement ever gets "the full power of your GPU" because your GPU doesn't do anything with movement. That sounds like you have a badly programmed cube or a badly programmed camera. If you have problems that arise from the framerate being too high, your code is framerate-dependent and that's a problem for you to fix, not a Unity bug.
We're working on our first game and our player (a ball) is moved along the scene with quite high velocities and jitter is a huge issue. We use an addForce to make it more fluent and do that in the FixedUpdate along with all of the other physics, we now moved the camera to update in the FixedUpdate too and yes, we might be 1 frame behind, but at least it's consistant and there's no issue of jitter at all anymore. Thank you for this solution, it's something logical but easy to be overlooked when you're further in the project.
if the camera transform is being calculated before or after the skater, one of the transforms will always be out of sync. pass the skaters position to a variable inside the camera script after you update the skaters position and use that to calculate the camera.
My problem was completely different from the above. I was updating my camera's position to follow a 3rd person object on screen in LateUpdate. If I tried rotating the camera up/down *after* updating the position, it was jittery. But if I switch the order of the lines so that it would rotate the camera up/down *before* updating the camera object's position, the jitteryness is gone or at least not noticeable. I did not have any jitteryness with the y-axis (left/right) rotation, but it was rotating around the 3rd person object. The up/down rotation was rotating using the main camera's transform. It's very strange that this made the difference, but I'm glad it did and hope it might help someone else. tl;dr changing my code to change camera rotation *before* camera position fixed my issue.