Thisara
Thisara

Reputation: 664

How to slow down slider value

I decrease the maxFuelCount value by -1. the counter goes down as expected.but it goes very fast when I long press the pedal. how can I slowdown counter value? I tried this * Time.deltaTime / 1.5f its works, not as I expected. can anyone suggest a method or give any guidance

Many thanks for your help

private void FixedUpdate()
    {
        if (move == true)
        {
            // decreasing the float value
            maxFuelCount--;

            if (maxFuelCount > 0 && timeLeft > 0)
            {
                rb.AddForce(transform.right * engineCapacity * Time.fixedDeltaTime * turboCapacity, ForceMode2D.Force);
                //asigning the decreased value to the slider
                UIBS.NewValue = maxFuelCount * Time.deltaTime / 1.5f;

            }

          }
     }

enter image description here

Upvotes: 0

Views: 461

Answers (1)

Ali Kanat
Ali Kanat

Reputation: 1889

Well you decrease 1 each frame gas is pressed. In one second with 50 fps it will almost decrease 50 which is a lot. Just lower the amount which decreases the MaxFuelCount. You can maybe use MaxFuelCount -= Time.deltaTime;

To make it even better you can use a speed counter which can be adjusted based on the terrain features such as if you are in mud fuel consumption speed increases like this:

MaxFuelCount -= Time.deltaTime * speed;

Increase or decrease the speed to an extent which you are comfortable about the speed.

Also UIBS.NewValue = maxFuelCount * Time.deltaTime / 1.5f; this will not work. Again with 50 fps you divide the value to almost 33 this time which will lower the value extremely fast.

Also it makes more sense to hold two variables as MaxFuelAmount (amount of fuel the tank can hold) and CurrentFuelAmount.

Then you can calculate percentage like: CurrentFuelAmount / MaxFuelAmount * 100 and use it in your UI value.

Upvotes: 3

Related Questions