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
1
Question by chillypacman · Oct 08, 2011 at 06:39 AM · c#physicstime

Stop physics without using Time.timeScale = 0?

Short of makinga ll bodies in a scene static is it possible to stop physics updates from happening without disabling time altogether?

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

6 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by roamcel · Oct 08, 2011 at 07:05 AM

Well you can set a rigidbody's iskinematic attribute to TRUE to stop its automatic world interaction.

There's many cases in which that would not suffice, but perhaps in your case it's enough. Whenever you want to 'stop motion', you will need to cycle all relevant scene objects and their rigidbodies, and set their iskinematic attribute to true.

Comment
Add comment · Show 5 · 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 chillypacman · Oct 08, 2011 at 09:37 AM 3
Share

Yeah I ended up doing as you suggested and saving the velocities of all rigid bodies so I could restore them after making them unkinematic.. pity ther eisn't a more elegant solution (i.e. halting physics by timestep).

avatar image Martijn Hendriks · Oct 08, 2011 at 09:58 AM 0
Share

Have you added the comment to the wrong answer, or am I not understanding you correctly?

avatar image chillypacman · Oct 08, 2011 at 10:11 AM 1
Share

I was justing adding to what you were saying, setting a rigidbody to kinematic doesn't only freeze dynamic bodies but also takes away their velocities so I had to save them then restore them on making them dynamic again...

avatar image Martijn Hendriks · Oct 08, 2011 at 10:59 AM 0
Share

Ok, my misunderstanding then

avatar image roamcel · Oct 08, 2011 at 04:00 PM 2
Share

I'm happy that you sorted it out, Jabber. Well done.

avatar image
4

Answer by ThomLaurent · Sep 29, 2014 at 12:30 AM

For me the problem was a little more complex : I had to pause a Gameobject's Rigidbody and resume it in order to have an animated pause menu.

So, to fix it I proceed as follows :

  1. Save your rigidbody.velocity (instance)

  2. Pause the rigidbody using rigidbody.Sleep() or rigidbody.isKinematic = true (both on your rigidbody instance)

  3. Wait until the player wants to resume...

  4. Resume the rigidbody using rigidbody.WakeUp() or rigidbody.isKinematic = false (both on your rigidbody instance)

  5. Set up your rigidbody.velocity (instance) with the one you saved at the first step

Here is an exemple :

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour {
 
     private Vector3 velocity;
     
     void Update () {
         if (Input.GetKeyDown(KeyCode.Space)) {
             // Pause the game when the player hit the Space key
             velocity = rigidbody.velocity;
             rigidbody.isKinematic = true;
         } else if (Input.GetKeyUp(KeyCode.Space)) {
             // Resume the game when the player release the Space key
             rigidbody.isKinematic = false;
             rigidbody.velocity = velocity;
         }
     }
 }
Comment
Add comment · Show 2 · 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 Bunny83 · Sep 29, 2014 at 01:13 AM -1
Share

Uhm, isn't that exactly what chillypacman used as solution? Have you read his comment on the selected answer?

Also you do not save the angularVelocity of the rigidbody. If your objects aren't rotated by forces that might be not important, but for a general solution it should be included.

avatar image pixxelbob · Jan 19, 2016 at 09:15 PM 2
Share

I would argue that this answer is more complete. As just making an object kinematic is not sufficient to enable an object to be reactivated retaining the previous state of movement.

avatar image
2

Answer by Martijn Hendriks · Oct 08, 2011 at 07:55 AM

I think it is possible to set the global Physics.sleepVelocity and Physics.sleepAngularVelocity to very high. this way your rigidbodies will fall asleep ignoring the system. But in order to get them back, you need to Awake all your rigidbodies I guess after setting the sleep parameters back.

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 Danielp299 · May 24, 2019 at 12:47 AM

Edit->Project Settings->Physics->auto simulation unable

alt text


unity-cubo2d-2019-unable-physys.png (76.6 kB)
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 radiatoryang · Mar 09, 2021 at 10:17 PM 0
Share

As of Unity 2017+, this should be marked as the better correct answer now. Thanks! (more info on Physics.autoSimulation -- https://docs.unity3d.com/ScriptReference/Physics-autoSimulation.html)

avatar image
0

Answer by AquaGeneral · Nov 11, 2011 at 06:22 AM

There are many ways to make an object static, the following are in my opinion the best:

  • Rigidbody.Sleep(). This would definitely be the cleanest and simplest.

  • Destroy the rigidbody component. When you want the objects to no longer be static add the Rigidbody component back.

Roamcel's method doesn't actually help performance, since you would making the objects kinematic will make it have to check for collisions regardless.

Martijn Hendriks's method is fine but not the greatest. If you were to go down this path you would be better off setting these settings indiviudally. Rigidbody.sleepAngularVelocity and Rigidbody.sleepVelocity.

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 Pangamini · Nov 19, 2012 at 03:46 PM 0
Share

In some cases it might be sufficient to deactivate the rigidBody containing GameObject, provided you don't have any renderers or other components attached (this is my case, i have rigidBodies separated from actors and actors being "springed" to their rigidBodies for smoothing lag ) and all rigidBodies are parented to single gameObject so all i have to do is call SetActiveRecursively and all my physics stops

  • 1
  • 2
  • ›

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Don't understand why this on collision script doesn't work. 2 Answers

Distribute terrain in zones 3 Answers

How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers

How to alter a script from the forum? 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