gradually raise moving speed but got different results on different devices

I have an idea to make moving bugs(i.e. animals) raise their speed gradually. So I have the following code :

float m_speedRatio = 1;
float m_fracJourney = 0;

void Update(){
    m_speedRatio += 0.01f

    m_fracJourney += 5f * Time.deltaTime * this.speedRatio;	
    transform.position = Vector3.MoveTowards( fromVec3, toVec3, m_fracJourney );

As you can see, every bug with this script will move towards the target position, toVec3. In the environment of my notebook, this caused an a little bit slower moving speed, but it made a crazy fast speed in my desktop PC.

How can I fix it to make my game have the similar playing speed no matter it runs on any device ?

My project’s TimeManager settings :

  • Fixed Timestep setting : 0.02
  • Maximum Allowed Timestep : 0.3333
  • Time Scale : 1

Thanks !

Your problem is on line 5. You increase by a fixed amount every frame. On some devices, your frame rate might average only 30 fps, on others, 100 fps.

You can handle this one of two ways. You can scale your m_speedRatio by Time.deltaTime:

m_speedRatio += 0.6 * Time.deltaTime;

Or you can move your scale of m_speedRatio into FixedUpdate() where you have a fixed frame rate for the increase.