[FIXED] Lags on a camera movement (or a player movenent)

Hello All,

Unfortunately, I have faced an issue that looks quite tricky for a beginner.
When a player moves along the scene It seems a playground periodically lags.
I guess the root cause is related to a player movement approach or to a camera that follows the player.

The cinemachine is used as a camera.
Please, take a look below for the camera settings and the movement script:

Player’s RigidBody2D:
4836908--464339--upload_2019-8-8_22-43-40.png

public class PlayerController : MonoBehaviour
{
    [SerializeField]
    private float speed = 1;
    [SerializeField]
    private Vector2 lookDirection = new Vector2(1, 0);

    private Rigidbody2D rigidbody2d;
    private Animator animator;

    // Start is called before the first frame update
    void Start()
    {
        rigidbody2d = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
    }

    void FixedUpdate()
    {
        float horizontalMovement = Input.GetAxis("Horizontal");
        Vector2 movement = new Vector2(horizontalMovement, 0.0f);
        Vector2 position = rigidbody2d.position + movement * speed * Time.fixedDeltaTime;

        if (!Mathf.Approximately(horizontalMovement, 0.0f))
        {
            lookDirection.x = horizontalMovement;
            lookDirection.Normalize();
        }

        animator.SetFloat("Speed", movement.magnitude);
        animator.SetFloat("Direction", lookDirection.x);

        rigidbody2d.MovePosition(position);
    }
}

PS: I have tried to google the issue and saw a lot of topics but neither of them has helped.

Thanks All in advance.

SOLUTION:
The root cause was that I have not tried to build and run with enabled Interpolation.
Due to I have enabled Interpolation and tried it only with Unity emulator It produced jerking and I have thought Interpolation has not fixed the issue.

So that, Guys, I would recommend trying to build with enabled Interpolation and run your game.

Is your camera movement in LateUpdate rather than Update?

Hi orchard800,

There is a screenshot with the camera settings above.
The camera update is set to Smart Update.
I have tried to change it to Late Update and Fixed Update but it produces more stutters.

Hopefully fixed the issue!
The root cause was that I have not tried to build and run with enabled Interpolation.
Due to I have enabled Interpolation and tried it only with Unity emulator It produced jerking and I have thought Interpolation has not fixed the issue.

So that, Guys, I would recommend trying to build with enabled Interpolation and run your game.