Camera Jitter / Stutter

Hi!

Is it possible to use Rigidbody.MovePosition instead of velocity to move a character followed by the camera without any stutter / choppiness? I’ve been searching for days :frowning:

Exactly the same problem as here:

Enabling ‘interpolate’ fix half of the stutter:
'While interpolation, horizontal translation in FixedUpdate and LateUpdate completely fixes the jitter on y axis, both on player and the scene, they introduce jitter on the x axis. ’

Setting the velocity fix the problem but this is discouraged because it may break the physic, so i’d prefer avoiding it.

The project is 3d platformer, with lot of fast movement, run, jump, so stutter is really important.

Thanks! This forum is a really strong help.

Thanks alexi but the camera already moves in LateUpdate, no parenting. As said above it's the same situation as here: http://answers.unity3d.com/questions/931654/synchronise-translation-with-physics.html#comment-1012178

–

The camera LookAt the player, but even when slerping the rotation or lerping the position to have smooth movement, either the player or the background slightly stutter (this is more visible in fullscreen resolution).

–

Is your camera following behind your player and angled slightly downwards?

–

Both back tracking and free mode were tested. Yes camera height > player position.

–

Post the code that deals with camera height. The downward angle part of my inquiry was important by the way :P

–

2 Answers

2

Instead of parenting the camera directly to the character, why not make the camera interpolate towards the character’s position over time? This would smooth out the camera movements and remove the stutter from the visuals.

If you set the lerp speed to be fairly high, then the position of the camera should be pretty similar to before as well.

Hi - when you say "it doesn't work", could you be more specific? What happens? compilation errors? runtime errors? the 'print' doesn't happen?... etc.

–

Also, please don't post extensions to your question, or comments about other people's answers as an "Answer". Instead you should edit your own question to include any progress you've made, or add scripts, and you should use the 'comment' feature to comment on any specific answers (for example if you have a question about any particular answer supplied)

–

I tried your script and it seems to work fine for me changing LateUpdate to FixedUpdate. The difference between the deltaTime calculated values in the camerascript and the fixedupdate-updated values of the player causes a small oscillation around the maximum distance point, which is basically your object jitter. You can see this when you Debug.Log the distance. In FixedUpdate this value becomes pretty fixed when moving.

If you really really want to use Update() or LateUpdate() you can try this:

Make a timer in FixedUpdate which records the total fixedDeltaTime passed since the code had last run in Update. Use this variable instead of Time.deltaTime in the code and reset the timer when you are done with the data.

This should help sync up the number of steps calculated for the player with the steps moved by the camera.

void Update()
{
    Vector3 camForwardZ = transform.forward;
    camForwardZ.y = 0.0f;        
     
    float currentDistance = Vector3.Distance (transform.position, player.position);            
 
    transform.position = transform.position + ((camForwardZ * (currentDistance - distance_max)) * 3f * timer);            
    transform.position = new Vector3(transform.position.x,  transform.position.y + ((player.position.y + height) - transform.position.y)*timer*2f , transform.position.z); 
    transform.LookAt (player.position);        

    ResetTimer();
}    
	 
float timer = 0.0f;
	
void ResetTimer()
{
	timer = 0.0f;
}
void FixedUpdate()
{
	timer += Time.fixedDeltaTime;
}

> I tried your script and it seems to work fine for me changing LateUpdate to FixedUpdate Thanks for your input meat5000. But that's strange, i still got the stutters when using FixedUpdate (tested on two computers, nvidia and ati cards). I tried your script too. Have you checked it doesn't stutter when building the game? Anyway I got tired of this and i've switched my player physic to Character Controller, moving in update(), loosing the benefits of a rigid body physics, but the camera doesn't stutter now. Looks like it's inherent to the FixedUpdate behaviour.

–

Holy crap, this actually fixed my problem! Thanks so much!

–