F
F
FantomBog2021-05-16 22:03:05
Unity
FantomBog, 2021-05-16 22:03:05

How to make gradual increase in speed in unity?

Briefly about the game, flappy board with a gradual increase in speed.

For a long time I was looking for information on how to make the movement speed gradually increase, but in the end I did not find anything, so I am writing here.

Here is the code that I have now (without gradually increasing the speed)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PipeMove : MonoBehaviour
{
    public float speed; // скорость для движения труб

    void Update()
    {
        transform.Translate(-speed * Time.deltaTime, 0, 0); // движение труб
    }
}


Thank you in advance :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-05-17
@FantomBog

Get a class that will recalculate the speed multiplier on the update depending on the elapsed time at a given level with a public property like

public float GameSpeedMultiplier {get; private set;}
and pass this script to all PipeMode classes and multiply by this factor.
Option 2 - change the frequency of the Update call and the value of Time.deltaTime, but this option is worthless, it can backfire in the rest of the logic or further in the game.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question