Camera is twitching

There is the Movement script:

public const float ROTATE_SPEED = 15f;
    public float movementSpeed = 5f;
    public Joystick MovementJoystick;
    private CharacterController _characterController;
    private Transform _mainCameraTransform;
    void Awake()
    {
        _characterController = GetComponent<CharacterController>();
        _mainCameraTransform = Camera.main.GetComponent<Transform>();
      
    }
    void Update()
    {
        var movement = _mainCameraTransform.TransformDirection (MovementJoystick.GetAxis ("Horizontal"),
                                                            0f,
                                                                MovementJoystick.GetAxis ("Vertical"));
        movement += Physics.gravity;
        movement *= Time.deltaTime;
        _characterController.Move (movement * movementSpeed);
    }
}

And the camera code:

 public Joystick RotateJoystick;
    public float RotationSpeed = 10f;
    private Transform _transformCache;
    private Transform _parentTransformCache;
     float rotationX;
     float rotationY;
    void Awake()
    {
        _transformCache = GetComponent<Transform>();
        _parentTransformCache = _transformCache.parent;
    }
    void LateUpdate()
    {
        if (RotateJoystick != null)
        {

            rotationY -= RotateJoystick.GetAxis("Vertical") * RotationSpeed * Time.smoothDeltaTime;
            rotationY = Mathf.Clamp(rotationY, -20, 40);
            rotationX += RotateJoystick.GetAxis("Horizontal") * RotationSpeed * Time.smoothDeltaTime;
            rotationX =  rotationX % 360;
            _parentTransformCache.localEulerAngles = new Vector3(rotationY,  rotationX);

        }
    }

Thanks :slight_smile:

Try changing your Update to a FixedUpdate() if you are using physics, or else try changing your camera LateUpdate() to an explicit update call that you call externally from the other update so you can control order of execution precisely.

I tryied FixedUpdate, it is worse than with LateUpdate.
It is twitching only when I use both movement and rotation joysticks.