Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Johan 4 · Mar 04, 2011 at 11:03 PM · timegravitytimescale

Decreasing timescale for a single object.

Is it possible to somehow decrease or increase timescale only for one object instead of the entire world? Also is it possible to change gravity for a specific rigidbody only?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by yoyo · Mar 05, 2011 at 12:37 AM

For the timescale, you could use an object-specific multiplier in all your own time-based calculations -- something like elapsedTime = Time.deltaTime * myTimeScale. Whether this is effective or not depends on how much control your code has over the things being updated.

For rigidbody physics, you could adjust the mass and drag of the rigidbody to see if you can get the effect you want. If not then set rigidbody.useGravity = false and use rigidbody.AddForce to add your own gravity, with a different gravitational constant.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by petrucio · Mar 13, 2012 at 02:55 AM

The private timescale multiplier in it's simple form will not work with a timescale of zero. This is what I did to have a logical Timer that can be paused while the rest of the game continues on it's usual pace:

 using UnityEngine;
 using System.Collections;
 
 //=========================================================================
 // Class: TimeKeeper
 // Mirrors Unity's Time.time, allowing the game to be logically paused
 // while the animations, UI, and other Time.time dependant tasks keep running at the usual pace.
 // TimeKeeper can be paused by the game when timestamp is set to 0,
 // or by the user pressing the Pause/Break key.
 //=========================================================================
 public class TimeKeeper : MonoBehaviour {
 
     // Variable: time
     // Access TimeKeeper.time to keep track of time with a different timescale then Time.time (read-only)
     public static float time {
         get { return instance.mTime; }
     }
 
     // Variable: timescale
     // Current timescale of the TimeKeeper.
     public static float timescale {
         get { return instance.mPaused ? 0 : instance.mTimescale; }
         set { instance.mTimescale = value; }
     }
 
     //=========================================================================
     private static TimeKeeper instance;
 
     private float mTime = 0.0f;
     private float mTimescale = 1.0f;
     private float mLastTimestamp = 0.0f;
     private bool  mPaused = false;
 
     //=========================================================================
     void Start ()
     {
         if (instance)
             Debug.LogError("Singleton violated (ooh!)");
         instance = this;
         instance.mLastTimestamp = Time.realtimeSinceStartup;
     }
 
     //=========================================================================
     void Update ()
     {
         if (Input.GetKeyDown(KeyCode.Pause))
             this.mPaused = !this.mPaused;
 
         float realDelta     = Time.realtimeSinceStartup - this.mLastTimestamp;
         this.mLastTimestamp = Time.realtimeSinceStartup;
         this.mTime += realDelta * timescale;
     }
 }

I did it with my needs in mind - you could 'un-Singletonize' that and have an arbitrary number of TimeKeepers and attach them to your objects.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Broesel82 · Dec 12, 2011 at 10:40 PM

Can anyone please help me with this problem. I use timescale to freeze the game. But while still everything is freezed i want to do the movement in "normal" speed. For the movement i use the first person controller from unity. But i still dont know how to assign this "private time.timescale".

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by by0log1c · Mar 05, 2011 at 02:04 AM

Much similar to yoyo's idea. You could try something like this, in JS:

function Update(){ myTimeFactor = 1; myTimeScale = Time.timeScale * myTimeFactor;

 //transform.Translate(Vector3.forward * myTimeScale);

}

I did not test it, but I believe this should create a 'private Time.timeScale' .

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to return unity back to its normal time scale and fixedDeltaTime 0 Answers

Can you lerp an object when Time.timeScale = 0? 1 Answer

C# | How to disable gravity for a certain amount of time? 1 Answer

Time not slowing down on iPhone 3 Answers

Script is only working when slowing down timescale 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges