Initial lag when updating velocity values in FixedUpdate

FixedUpdate() {
    rigidBody2D.velocity = transform.up * speed * amplification;
}

I have an object that starts out going really fast and then gradually goes slower until is reaches X speed. Currently I have it so that I tween the “amplification” value from 30 to 1 over 1 second, then the object proceeds to move at its normal velocity.

Using this method, upon app startup on android, the first time this object appears (2 at a time), the frame rate plummets from 30 to ~15 for about a second. Then all subsequent objects, even after a scene reset, don’t affect the frame rate at all until the app is restarted.

So my question is, why the initial lag, but afterwards it’s fine? And is there a better way to code this initial burst of speed while still having rigidbody2D velocity control the object’s normal speed?

Bump

  1. Can you provide the full code for this class? At least the relevant parts.

  2. did you try waiting a few seconds before creating the first speeding objects? Perhaps the slow down is caused by something else entirely.

  3. what unity version are you on.