Seemingly random frame drops during playmode

I have a very simple character controller and a very simple test level which is basically just grey cubes, and for some reason the game window keeps randomly dropping and the game will glitch out for a second. Here is what it looks like in the profiler, but if I’m being honest I have no clue what it means.

and here is my player script, which I dont think would be the problem, but you never know.

public class player : MonoBehaviour
{
    public float speed;

    Rigidbody rb;
    public Transform Cam;
    bool grounded;

    Vector3 moveDir;
    public float JumpHeight;
    float mouseX, mouseY; 

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.freezeRotation = true;
        Cursor.lockState = CursorLockMode.Locked;
    }

    float xRotation;

    // Update is called once per frame
    void Update()
    {
        GetInput();
        transform.Rotate(0, mouseX, 0);
        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        Cam.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    }

    void FixedUpdate()
    {
        if(grounded)
        {
            rb.AddForce(moveDir * speed, ForceMode.Force);
            rb.drag = 6;
        }else
        {
            rb.AddForce(moveDir * speed / 3, ForceMode.Force);
            rb.drag = 2;
        }

        if(grounded && Input.GetButton("Jump"))
        {
            rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
            rb.AddForce(Vector3.up * JumpHeight, ForceMode.Impulse);
        }

    }

    private void GetInput()
    {
        moveDir = (transform.forward * Input.GetAxis("Vertical")  * speed + transform.right * Input.GetAxis("Horizontal") * speed); 
        grounded = Physics.Raycast(transform.position, Vector3.down, 1.1f);
        mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * 400;
        mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * 400;
    }
}

This Profiler data shows a changes between 1000 & 2000 FPS. I could end just stating that.

Mate, this is not how performance issues looks like.

If your game is completing a full game loop in around 1 ms - it means these (1ms) “spikes” represent a brief moments where your CPU wasn’t bored to death and calculated something.

EDIT:

The problem with this screenshot is that it is not showing the details of the spike event

  1. Find the the exact frame where this ugly freeze happened (click on this frame)
  2. After selecting this problem-causing frame the view below will show what has happened there to cause such a freeze - do a screenshot of that and share it

Alternatively there is a Save icon above. You can share this file too. It will be big but it will contain everything there is to know about the recorded events.

Here is a better screenshot of the profiler


compared to the frames with no freezing it seems “Physics.Processing” is taking more time? not really sure why this might be happening though.

video of what the freezing looks like

You need to know that following a Rigidbody with a Camera results in these kind of issues. Every time. It’s just not always immediately apparent. It’s harder to notice in your case because you’re running at like gazzilion FPS. If you test this project on a much older machine the jitter will become much more apparent.

  1. Make sure you are moving this Rigidbody by velocity and not moving it around by changing it’s position.
  2. Change Rigidbody’s Interpolate property to Interpolate value.
  3. Try again.