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 Lockstep · Jun 10, 2013 at 03:05 PM · physicsrigidbodypause

Stop physics without Time.timeScale

Hi. I'm looking for a cheap way for stopping the physic simulation.

In my game you basically roll around a ball using physics. When the ball hits the finish, I want the ball and every other rigidbody to stop. However I also want to use particle effects afterwards, so I can't set Time.timeScale to 0.

I've tried to set every(Rigid)bodys velocity to 0 during FixedUpdate, but they were still moving slowly under gravity. Besides this seems too crude to me anyways.

Thanks alot.

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

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

Answer by zombience · Jun 10, 2013 at 03:18 PM

have a manager somewhere that registers all of your rigidbodies. then, when you need to stop them, go through the array or list and set something like:

 public List<Rigidbody> physObjects = new List<Rigidbody>();
 
 
 public void AddRigidbody(Rigidbody r)
 {
     physObjects.Add(r);
 }
 
 public void DisablePhysics()
 {
     foreach(Rigidbody r in physObjects)
     {
         r.isKinematic = true;
     }
 }
 
 public void EnablePhysics()
 {
     foreach(Rigidbody r in physObjects)
     {
         r.isKinematic = false;
     }
 
 
 }
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 Bunny83 · Jun 10, 2013 at 03:24 PM 0
Share

right and for a true pause script (so you can resume later) you would save the velocity and angularVelocity of each Rigidbody and restore them on resume.

avatar image Lockstep · Jun 10, 2013 at 03:57 PM 0
Share

Thanks for your reply. I tried:

 void DisablePhysic(){
         Rigidbody[] rigs = (Rigidbody[]) GameObject.FindObjectsOfType(typeof(Rigidbody));
         foreach (Rigidbody r in rigs){
             r.velocity = Vector3.zero;
             r.useGravity = false;
             r.is$$anonymous$$inematic = true;
         }
     }

,but I got an error: Actor::setLinearVelocity: Actor must be (non-kinematic) dynamic! The movement seems to stop correctly though.

avatar image Scribe · Jun 10, 2013 at 04:04 PM 0
Share

$$anonymous$$aybe you are trying to set the velocity to something in another script or part of the script. If you double click on the error what line of code does it send you to?

avatar image zombience · Jun 10, 2013 at 04:10 PM 0
Share

hmm, strange error. not sure. it appears that unity believes that the rigidbodies are kinematic BEFORE you set the velocity to zero (kinematic rigidbodies have no velocity). if you want them to stop and never need to start them again at their previous velocity, however, that step is redundant to is$$anonymous$$inematic = true;

if your original question is answered, don't forget to mark this question as answererd.

avatar image Lockstep · Jun 10, 2013 at 04:32 PM 0
Share

Thanks a lot guys. Seems like I had a kinematic rigidbody left, which I wasn't aware of. It works perfectly now.

if your original question is answered, don't forget to mark this question as answererd.

I always do this, when I'm happy with the answer.

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

17 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Friction between two rigidbodies 0 Answers

Moving a player with Rigidbody 2 Answers

Disable inertia tensor calculations on rigidbody? 0 Answers

Problems with Configurable joint in 2d Configuration 0 Answers

Raycast on ball 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