Inconsistent glitchy player movement when playtesting

I was tweaking my PlayerMovement script in my 3D FPS game (script responsible for reading inputs from the player to control their own body, moving around and jumping), and I ran into a very odd issue.

Sometimes, when I playtest in the Editor the movement is very glitchy and laggy, it’s like the player is teleporting each meter instead of actually moving, and the inputs don’t work properly, the player sometimes moves in directions different from the input directions, and the speed that they move in varies greatly. This glitch is not consistent, so sometimes movement works as intended, and sometimes it happens partially. It also only happens in one of my scenes specifically, in the other scene it seems to happen to a much lesser degree and is harder to notice.

This didn’t happen before I tweaked my PlayerMovement script based on a tutorial I was recommended earlier (Physics), so I think it has to do with that. Also, when I profile it seems that whenever the glitch is happening the Physics systems seem to eat a lot more CPU than usual. The part of the script I assume is causing it is provided below:

        //Main movement shenanigans//
        TargetVelocity *= CurrentSpeed;
        float CurrentMaxAcceleration = (Grounded ? MaxAcceleration : MaxAerialAcceleration);

        Velocity.x = Mathf.MoveTowards(Velocity.x, TargetVelocity.x, CurrentMaxAcceleration);
        Velocity.z = Mathf.MoveTowards(Velocity.z, TargetVelocity.z, CurrentMaxAcceleration);

        PlayerRigidbody.velocity = Velocity;
        //Main movement shenanigans//

Any solutions?

Update on the issue: It seems to be only happening when testing the game in the Editor. It’s close to or completely absent from the built versions, if I am guessing this correctly. It also seems to happen more often and with greater intensity after testing the scene multiple times in a row.

I was using TargetVelocity to track the player’s input in void Update() and using it as the velocity in FixedUpdate() at the same time, causing the glitchy movement. Changing the variable used seemed to have fixed the issue.