Camera shaking due to different updates

I’m making a 3rd person camera, in the video I show what the design and code is in the camera, the main problem is that when the camera goes down or up, it shakes, turning around and following the character works fine.

Why does this problem arise - the character moves with a fixed update, this is necessary for a network game, so a regular update will not work for him, on the other hand, if the camera is set to a fixed follow update, the picture will not be smooth.

As a result, I had this problem - how can the camera smoothly follow a target that is moving in a fixed update?

(we are not discussing the cinema machine…)

Sadly, because Cinemachine can run in fixedupdate. :wink:
How much time went into making the camera? It may not be too late to adapt.

Regardless of that, without seeing any code we cannot provide direction.

The following camera code is simple

public class ControllerCamera : MonoBehaviour{
    public float SmoothMovement = 0.3f;
    public Transform Tcam;
    public Transform CameraHolder;
    public Transform CameraLook;
    private Vector3 refMove = Vector3.zero;

    private void Update(){
        Tcam.position = Vector3.SmoothDamp(Tcam.position, CameraHolder.position, ref refMove, SmoothMovement, Mathf.Infinity, Time.deltaTime);
        }

    private void LateUpdate(){
        Tcam.LookAt(CameraLook);
        }

    }

The character control code is also simple, choosing a direction in a regular update

private void UpdateMovement(){
        Horizontal = Input.GetAxis("Horizontal");
        Vertical = Input.GetAxis("Vertical");
        if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)){ Shift = true; }else{ Shift = false; }
        DirMove = DirLook.forward * Vertical + DirLook.right * Horizontal;
        DirMove.Normalize();
}

but the movement itself in a fixed

private void FixedUpdate(){
        if(DirMove != Vector3.zero){
.......
            transform.position += DirMove * Speed * Time.fixedDeltaTime;
.........

I chose the most necessary…

I was thinking of creating an “invisible character” who would move in a normal update and the camera would follow him, but then the character himself would shake, maybe update them in a normal update and move the invisible fixed position and adjust the position of the normal update to the fixed one…
but what is the best way to do this then?

(I don’t use RigidBody or CharacterContoller)

First thing I’d check is if the object the camera is following (and any of its parents) is stable on the Y axis, or does it follow the terrain and does bumps up/down while moving?

Try logging the position Y value before and after smoothdamp.

I wouldn’t be surprised if the issue is due to camera running in update whereas movement occurs in fixed update. Given how smoothdamp works, you need to make sure that the second parameter (CameraHolder.position) represents the player’s current target position, meaning where it will be in the next FixedUpdate. If I get this correctly you are effectively smooth damping to the target position in a single update frame (you provide deltaTime as the timestep). Which means every frame where there is no fixedupdate (default: 50 Hz, update: 60 Hz or more) the camera is already at the target position and doesn’t move, so that would be like a stop & go.

Try passing in fixedDeltaTime, this should dampen the movement over more than one update frame.

You don’t need to multiply with fixedDeltaTime because it is a constant (the same value you set in project settings for fixed timestep).

Anyhow, still thinking you should pick Cinemachine because you work with a 3rd person view and given the environment, you absolutely do not want to have to struggle with camera collision avoidance yourself. The camera is clipping through the terrain and walls, which is a non-trivial challenge but easy to prevent with Cinemachine since this is a built-in feature, and highly configurable.

my idea of moving both the normal and fixed position at the same time seems to be working, now I’m testing and see that the fixed position almost coincides with the normal one, you can also refine it with a method that will slow down or speed up the normal position, but the most important thing is that everything else moves smoothly.

Question about camera collisions, is it possible to somehow fire a beam and find out if it hits something even if it doesn’t have a collider? that is, detect meshrenderer? Is this possible or are only colliders needed?

p.s. - I don’t want to use both the cinemamachine and the other add-ons, I just don’t want to…

although this is no longer necessary, all obstacles still have colliders…

Well, that’s up to you. You just have to consider whether you’re up to the task AND time it takes to implement complex tasks that are already handed to you for free. :wink:

The funny thing is that no matter how many times I tried different add-ons, they individually worked as they should, but as soon as there were several of them and I tried to adjust them all to my project…
it became confusing and confusing. for some reason it’s easier for me to write myself, at least I understand where and what I have…

I think this has already turned out better, but some details need to be finalized…

This is the spot that under the character is a fixed position, it is clear that over time it diverges, this is what I am working on now, that is, I will synchronize them…