Weird framerate issues

Hello, everyone!

New:
Putting everything from Update to FixedUpdate fixes problem. But why?

Description of project

I recently decided to finally finish some of mine projects, but I just ran into a brick-wall.
I have a game which is about flying in corridors, dodging and shooting. I have already built up all intended features and tested them in demo level. Everything was fine.
Then I started making first levels and the game began to lag. I thought that it may be something with too many objects or rigid bodies. So I separated environment to graphical (no colliders, just render) and collisions (Game is 2D, so no problem). Just to be sure I reinstalled Unity to 2017.3.0f3 Personal (64bit).
Everything ran fine. Then out of nowhere lag appeared again and even retrospectively on every level, I made so far. I was unable to find out what causes this.

Problem

Movement of player is slowed down, bullets move slow and (may be important) trail renderer leaves a shorter trail than it should. The camera that follows player does not follow smoothly.
Player code for example:

void Update ()
	{
		if (!cr_sc.crashed && levelStarted) { //player didnt crashed and level was started
			float moveHorizontal = Input.GetAxis ("Horizontal"); //storing input
			float moveVertical = Input.GetAxis ("Vertical");

			float variableSpeed = moveVertical * speedChange; //applying slowing down or speeding up

                    //creating a movement vector
			Vector3 movement = new Vector3 (moveHorizontal * Time.deltaTime * turningSpeed, 0f,
				                  ((fixedSpeed + variableSpeed) * Time.deltaTime));
                    //moving player
			rigid.MovePosition (transform.position + movement);
                    //tilting player ship according to tilt value
			rigid.rotation = Quaternion.Euler (0.0f, 0.0f, moveHorizontal * -tilt);
		}
	}

I tried to run profiler. Now I will just sum up results of me trying to find a problem:

Time.timeScale is ok. (1f)

Time.deltaTime is usually 0.02f.

Memory usage max is 212 MB.

Average framerate is 500FPS - 250FPS

Building the project does NOT help.

Sometimes, framerate drops (= CPU usage graph goes up) significantly and game runs fine for a small period of time.

It looks like game runs *quicker and smoother when having less FPS.

  • camera follows nicely, trail renderer renders as intended trails…

Could you please help me?
Which tests should I try to locate problem?

Btw, I run this on new Dell laptop, games like DeusEx:Mankind Divided or Dishonored 2 runs fine and stable on medium settings.
My other Unity projects seems to be fine.

Intuitively I’d say re-check your time based calculations. According to your example, it seems that your acceleration is not considering time.

Now I’m just guessing but try changing this:

         float variableSpeed = moveVertical * speedChange;

to something like this:

         float variableSpeed = moveVertical * (speedChange * Time.deltaTime);