Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Mun-Yeong-Seok · Sep 13, 2017 at 01:24 AM · rigidbody3ddetectionstopsleeping

Rigidbody.IsSleeping() VS Rigidbody Velocity Comparison. Performance question for object stop detection.

 // 1
 if (rigidbody.velocity.sqrMagnitude < stopThreshold && rigidbody.angularVelocity.sqrMagnitude < stopThreshold)
 {
 }
 
 // 2
 if (rigidbody.IsSleeping())
 {
 }

Which way is faster? The value of stopThreshold is 0.0001f, and the value of Sleep Threshold is 0.005 (Default). The value of Sleep Threshold can be changed to a higher value. I'm curious about the inner code of IsSleeping().

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
0
Best Answer

Answer by Bunny83 · Sep 13, 2017 at 04:21 AM

IsSleeping certainly is slightly faster. However it's in the range you just shouldn't care. IsSleeping does not perform any kind of "test" on the velocity as it just returns the inner state of the rigidbody. The Rigidbody will determine it's sleeping state automatically. When a rigidbody falls asleep it basically deactivates the rigidbody and it's no longer included in any physics calculations until it wakes up again.

Using a smaller threshold than the internal sleeping threshold makes no sense. If a rigidbody falls asleep it's velocity / angularVelocity is set to 0 as from that point on the object is not moved anymore.

Of course collisions from other moving rigidbodies, applying forces or just moving the object manually will wake it up again.

ps: You usually want to use different values for the linear velocity and the angular velocity. While the sleeping threshold for the linear velocity would be different depending on your object scaling, the threshold for the angular velocity usually should be constant (as angles are not affected by scaling).

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 Mun-Yeong-Seok · Sep 13, 2017 at 11:33 AM 0
Share

Is this the key point?

  1. Set the value of the velocity comparison threshold to be equal or greater than the value of Physics$$anonymous$$anager's Sleep Threshold.

  2. Use a different threshold value for rigidbody.velocity and rigidbody.angularVelocity.

Lastly, 'the sleeping state is automatically deter$$anonymous$$ed' does it mean that it can be irregular as opposed to the velocity comparison?

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

98 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 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 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 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 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 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

Prevent rigidbody from colliding 1 Answer

How do i Clamp the Z position of a rigidbody? 1 Answer

Detect exactly where other objects around player are 3 Answers

How to know if gameobject is in a circle in my canvas? 1 Answer

How do i add a force to multiple objects in an area? 1 Answer


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