Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Slow down time but my player object doesnt return to normal speed.

Discussion in 'Scripting' started by gabrieldolbear, Aug 7, 2018.

  1. gabrieldolbear

    gabrieldolbear

    Joined:
    Aug 7, 2018
    Posts:
    3
    So basically, i tried to make a slow down script for my player and the world and then the speed should return to normal speed, and it seems like it does for less than a second but then just continues to slow down. (also im a coding fetus)

    using UnityEngine;

    public class TImeManager : MonoBehaviour {

    public float slowDownFactor = 0.05f;
    public float slowDownLength = 1f;

    void Update()
    {
    Time.timeScale += (1f / slowDownLength) * Time.unscaledDeltaTime;
    Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
    }

    public void slowDown()
    {

    Time.timeScale = slowDownFactor;
    Time.fixedDeltaTime = Time.timeScale * .02f;


    }

    }


    if anymore context is needed just tell me sorry i dont know much :/
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Keep copies of original timeScale and unscaledDeltaTime values somewhere so you can reset them when the "slow down" stops, maybe?
     
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    You're never resetting Time.fixedDeltaTime back to normal, only Time.timeScale. (Also you're not setting fixedDeltaTime to an appropriate number.)
     
  4. gabrieldolbear

    gabrieldolbear

    Joined:
    Aug 7, 2018
    Posts:
    3
    oh okey, well ill need to fix that then, thank you!
     
  5. gabrieldolbear

    gabrieldolbear

    Joined:
    Aug 7, 2018
    Posts:
    3
    ok, ill try that, thank you