Camera jittering on moving platform

Hi. I have a weird camera jittering while my player is on the moving platform
I use two cameras. One free-look camera and one virtual camera for my “aiming” purposes
When I step on the moving platform, on activating free-look default camera, my environment is jittering.
If I switch to my aim camera, the jitters transfer on my third person character.
Jitter amount is lowering when I look ahead, and raises when my character turn left or right.
I am using fixedUpdate to move my platform, since my character is rigidbody based.

Here is a simple video that visualize my problem: Imgur: The magic of the Internet

Am I missing something? Thanks in advance! :slight_smile:

Looks like the vcam and the character are not animating on the same clock.

  • What is the Update Method setting in CM Brain?
  • When the project is running, look at the inspector of the active vcam. Next to the “Solo” button, it will show how the vcam is being updated (FixedUpdate or LateUpdate). What does it read for your 2 vcams, when the jitter is happening?

Hey Gregoryl. My update method from main camera is set to “Smart update”
On game running It says “late update”
I tried switching it to “Fixed update” from the main camera. and that fixes the problem with platforms.
However this way, my character start jitters when he is not on the platform :smile:

What happens if you switch back to smart update and enable Interpolation on your platform’s rigid body?

I don’t have any rigidbody on the platform itself. I am using a script to move the platform using transform.position mainly.

In that case, it’s very likely that you aren’t moving the platform smoothly, or are not moving it exclusively in Update() or FixedUpdate().

If your target character is animating on FixedUpdate() - perhaps because it is a rigidbody - but your platform is moving on Update(), that is a problem because the camera won’t know how to follow it. What happens if you move the platform in FixedUpdate() only?

It is very weird… Actually, I am moving my platform using fixedUpdate… here is the full code : hatebin

Try changing
float distCovered = (Time.time - startTime) * speed;
to
float distCovered = Time.deltaTime * speed;

Sorry that suggestion was a little too naive. What I’m trying to get at is that this code

float distCovered = (Time.time - startTime) * speed;
float fractionOfJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(departTarget.position, destinationTarget.position, fractionOfJourney);

is questionable because of the use of time. Instead, can you try something like

var velocity = (destinationTarget.position - departTarget.position).normalized * speed;
transform.position += velocity * Time.deltaTime;

This way (both ways actually) breaks my functionality of the platforms :smile: … Maybe I should check my rigidbody. It’s weird that changing the main camera update method to “fixed update” from “smart update” fixes my problem with the platforms, but open a problem with my character controller…

My point is that this bit (Time.time - startTime) * speed should be replaced with something that relies only on Time.deltaTime. Adjust your code accordingly.

As for the update mode, it makes a big difference, and that has to do with the way Unity works with time. See this post for a detailed discussion: Camera Jitter, depending on the settings either the player or the environment jitters

I tried testing your code, just to see is there any difference in the behavior of the player after replacing Time.time with time.deltaTime.
I read the above topic and it is really informative.

The player still jitters on the platform. Is it possible the issue to be in my player controller script?

Yes it is possible.

1 Like

Ok. I don’t have any idea why this, but it gets actually better after I turn character controller rigidbody Interpolate from “Interpolate” to “None”
I hope it won’t affect on my physics

6764680--781393--upload_2021-1-25_23-42-43.png

https://forum.unity.com/threads/cam…-the-environment-jitters.822120/#post-5494891 will explain why.

What happens if you leave interpolation on, but move your platform in Update() instead of FixedUpdate()? That way everything will be happening on the render clock instead of on the physics clock, and the cameras will be happy.

The thing is that if I turn on interpolate of my character rigidbody only “left” and “right” movement is jittery… The forward and backwards movement is still smooth.

Video: Imgur: The magic of the Internet

After making platforms on update instead of fixedUpdate and turn on my interpolate I get jittery movement from the player not from the camera while the platform is moving.

I suspect that it’s equally jittery in all directions, only you don’t notice it front-to-back because the effect in perspective will seem very small when compared with side-to-side.

How does the player move when it’s on the platform? What makes the player not just stay still while the platform moves out from under him?

I am making a similar to platformer game, so I would have platforms that move constantly and my player needs to be able to jump precisely from one to another.

ok, but my question is: what is the mechanism that makes the player stick to the platform when the platform is moving?

Oh sorry. I am using very simple way to parent the player to the platform onCollisionEnter

 void OnTriggerExit(Collider other)
    {
     
        if (other.gameObject.tag == "Player")
        {
            other.transform.parent = null;
        }
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            other.transform.parent = transform;
        }
    }

I have a second box collider with trigger function on each platform