Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by PirateMonkey · Sep 15, 2014 at 08:33 PM · time.timescaleslowmotion

Time.timeScale is Having a Strange Effect on Physics

Hey all,

I am currently building a 2d physics-based game. I've built a moving character who can shoot bullets (which naturally travel much faster than the character).

Recently I've tried implementing slow-mo into the game by pressing space. The issue I'm having is that it seems to affect the physics-based objects in different and unexpected ways. The main issue is that the bullets become slower relative to the character - the lower the slow-mo timescale, the slower the bullet relative to the character. With a Time.timeScale as low as 0.1, the character can actually travel faster than the bullet and I have no idea why.

I have built a slow-mo script which fades in and out of slow mo by pressing the space bar. Relevant code:

 if (Input.GetKeyDown (timeSlow)) 
 {    
     slowOn = !slowOn;
 }
 
 Time.fixedDeltaTime = 0.02 * Time.timeScale;
 
 if(slowOn == true)
 {
     var pitchDown : float = gM.audio.pitch - (Time.deltaTime * pitchSpeedMultiplier);
         gM.audio.pitch = pitchDown;
         if(pitchDown <= slowPitch)
             {
                 gM.audio.pitch = slowPitch;
             }
     var slowDown : float = Time.timeScale - (Time.deltaTime);
     Time.timeScale = slowDown;
     if (slowDown <= reducedTimeScale)
         {
             Time.timeScale = reducedTimeScale;
         }
 }
 
 if(slowOn == false)
 {
     var pitchUp : float = gM.audio.pitch + (Time.deltaTime * pitchSpeedMultiplier);
     gM.audio.pitch = pitchUp;
     if(pitchUp >= normPitch)
         {
             gM.audio.pitch = normPitch;
         }
     var speedUp : float = Time.timeScale + (Time.deltaTime);
     Time.timeScale = speedUp;
     if (speedUp >= standardTimeScale)
         {
             Time.timeScale = standardTimeScale;
         }
 }    

Here is some of the relevant code from my bullet shooting script:

 //missile variables
 var missileFireRate : float = 0.5;
 private var missileNextShot : float = 0.0;
 var missilePrefab : Transform;
 var missileForce = Vector2(200,200);
 
 ...
 
 if(Input.GetKey(fireWeapon) && SubControl.isShotEnabled == true)
     {
         if(primaryActive == true && missileActive == true)
             {
                 if(Time.time >= missileNextShot)    //Time.time is the time since frame has started
                     {
                         //Code generates Missile, and instantiates in the location of the Turret
                         var missileInstance = Instantiate(missilePrefab, Vector3(transform.position.x, GameObject.Find("Suber").transform.position.y, transform.position.z - 0.03), transform.rotation);
                         missileInstance.rigidbody2D.AddForce(Vector2.Scale(TurretRotation.difference, missileForce));
                         missileNextShot = Time.time + missileFireRate;
                     }
             }
 
 ...


If anyone has any idea what's going on I would really appreciate the help!! :)

Comment
Add comment · Show 2
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 screenname_taken · Sep 15, 2014 at 08:45 PM 0
Share

How are you moving your character? is it via an animation made in a package, or in script?

avatar image Stormizin · Sep 15, 2014 at 08:49 PM 0
Share

When timeScale is set to slow-mo/zero the game is basically slowed/paused if all your functions are frame rate INDEPEDENT.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Sep 15, 2014 at 08:55 PM

Its recommended that you change the Time.fixedDeltaTime every time you change Time.timeScale.

http://docs.unity3d.com/ScriptReference/Time-timeScale.html

Comment
Add comment · Show 1 · 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 PirateMonkey · Sep 15, 2014 at 08:57 PM 0
Share

I think I did that though (see line 6 of first block of code)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Slow and Fast motion? 1 Answer

How to get a smoother slow motion 0 Answers

Time.timeScale is laggy 2 Answers

Time.timeScale not working 1 Answer

Powerup Timer not Working 3 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