Constantly change speed of player based on the given distances

Hi,

My game designer sends me a request like this attachment. He wants to constantly change the speed of the character based only the distances the player reaches. Ex: Increase constantly from 0 to 10 m/s in first 100 m. Then increase from 10 to 20 from 100-500m.
Since this is infinite running game, there will be no limitation for the distance.
Any one have the idea to achieve this?

Besides, there will be the Speed Up item. So how to apply it, for example if player takes it at 990 m?

Thanks.

83916-change-speed-based-on-distance.jpg

I’m assuming you have the controller functioning and have the ability to change speed values. Assuming that, you can have your speed increase by using Time.deltatime multiplied by a float.

float PlayerSpeed;
float Acceleration;

Start()
{
PlayerSpeed += Time.deltatime * Acceleration;
}

You’ll have to mess around with the math to get it matched to that graph but that is basically how you would do it.

Something along the lines of this would work. Obviously you add your own movement script and just use the float ‘movespeed’ to define your speed.

float moveSpeed = 0f,
        speedIncreaseRate = 0.05f;
    Vector3 startPosition;
    void Start()
    {
        startPosition = transform.position;
    }

    void Update()
    {
        moveSpeed = Vector3.Distance(transform.position, startPosition) * speedIncreaseRate;
        //Move Script
    }