Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to make some GameObjects not affected by timescale?

Discussion in 'Getting Started' started by ShinigamiUzi, Sep 30, 2017.

  1. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    I have this script, which when it collide with the player, the timescale slows down

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SlowDownTime : MonoBehaviour {
    6.  
    7.  
    8.     public static float slowTimeScale = 0.3f;
    9.     public static float normalTimeScale = 1f;
    10.     public static float timeOut = 8f;
    11.  
    12.     // Use this for initialization
    13.  
    14.     void OnTriggerEnter(Collider other)
    15.     {
    16.         if (other.tag == "Player") {
    17.             other.GetComponent<Player_Controller> ().StartCoroutine (CountDown ());
    18.             Destroy (gameObject);
    19.         }
    20.     }
    21.  
    22.     public static IEnumerator CountDown()
    23.     {
    24.         Time.timeScale = slowTimeScale;
    25.         yield return new WaitForSeconds (timeOut);
    26.         Time.timeScale = normalTimeScale;
    27.     }
    28.  
    29. }
    But I need to make it so that the timescale doesn't slow down for the player gameObject , is there any way? I know about time.unscaledtime but not sure how to implement it
     
  2. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    Basically, you have to go through every script that affects the player to use time.unscaledDeltaTime instead of time.deltaTime.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Multiple time scales is going to be a pain. Unity doesn't natively support them, so you'll have to do it yourself.

    In particular PhysX will only work with a single time scale. So if you want multiple time scales and physics, you will basically have to rewrite a large portion of the physics engine.
     
    Joe-Censored likes this.
  4. jchester07

    jchester07

    Joined:
    Jun 28, 2016
    Posts:
    24
    I was also looking for something like this and I found a video here.
    He posted his code here.
    I haven't tried it yet but it looks interesting. You can also try checking out Chronos made by ludiq.
    You can also check this links:
    http://answers.unity3d.com/questions/711749/slow-time-for-a-single-rigid-body.html
    https://forum.unity.com/threads/solved-slow-everything-but-the-player.323965/
    I prefer the first one as it is the same code with whats in the video.
    I'll be testing it out later on on how his code works.
     
    BugKiller likes this.
  5. thedublinboy

    thedublinboy

    Joined:
    Nov 18, 2017
    Posts:
    2
    I know this is an old post but you could just for example speed up or slow down a gameobject with anim speed and movement speed variables