• 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 /
This question was closed Aug 07, 2014 at 08:22 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by LordJesus · Aug 07, 2014 at 05:36 PM · physicsrigidbodytimetimescale

Physics behave weirdly after timeScale change

So I have this game where the player robot is able to fire a mortar gun (cannon balls). My code for firing mortars is this:

 GameObject m = Instantiate(Mortar, turret.transform.position + Vector3.up, Quaternion.identity) as GameObject;
 Rigidbody body = m.GetComponent<Rigidbody>();                   
 var direction = (turret.forward + turret.up * 1f) * 500;
 body.AddForce(direction);

And this works really well, this results in a cannon ball being fired about 21 meters away. However, I am doing some operations in my game that takes place as fast as possible (about Time.timeScale = 20). When I then set the timeScale back to 1 after completing these operations, the mortar will now fire with much greater force, and the cannon balls will travel over 100 meters with the same code.

It seems that the Physics system somehow hasn't registered that the timeScale is 1 instead of 20, so it will confuse the timings for the physics.

If I switch to another scene and back to the scene, the physics works fine again. Is there anything I can do to make the Physics behave properly when changing timeScales?

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Kiwasi · Aug 07, 2014 at 07:11 PM

Change Time.fixedDeltaTime by the same amount

Comment
Add comment · Show 6 · 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 meat5000 ♦ · Aug 07, 2014 at 07:31 PM 1
Share

Corrected your error ;P

avatar image Kiwasi · Aug 07, 2014 at 08:00 PM 0
Share

Thanks.

I don't commonly mess with timeScale and fixedDeltaTime, so while I'm aware of the principles I don't often put them into practice.

avatar image LordJesus · Aug 07, 2014 at 08:14 PM 0
Share

I'll try and look at that, but shouldn't Unity handle that for me? I mean, it has changed it from the correct value to some weird value when I went from timeScale = 1 to timeScale = 20, so I would expect it to just go back to the original value when I go back from timeScale = 20 to timeScale = 1.

avatar image LordJesus · Aug 07, 2014 at 08:22 PM 0
Share

That did the trick! For some reason, when I went from timeScale = 1 to timeScale = 20, the fixedDeltaTime went from 0.02 to 0.045, but going back from timeScale = 20 to timeScale = 1 did not change the fixedDeltaTime back. Setting it manually to 0.02 solved it. I still think that Unity should handle this both when setting timeScale up and down.

avatar image Kiwasi · Aug 07, 2014 at 09:17 PM 0
Share

Unity typically doesn't handle this because there are plenty of cases where handling it differently makes sense. I'm actually surprised that unity changed it at all.

Show more comments

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

TimeScaling & Rigidbody problem 0 Answers

Time.timeScale not working with Havok Physics 0 Answers

Slow Time for a single Rigid Body 5 Answers

Change of rigidbody.velocity, Update or FixedUpdate? 1 Answer

Slow motion for Physics game 2 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