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 Razion · Aug 11, 2012 at 08:09 AM · rigidbodyfreezeconstraintsquery

Query Rigidbody Constraints?

How do I go about checking if a rigidbody contains (among others) a specific restraint? Supposedly, I should be using:

 if (rigid.constraints & RigidbodyConstraints.FreezePosition)

However, this doesn't work. I get an error telling me that rigidbody.constraints can't be converted to a boolean.

Any ideas?

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

2 Replies

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

Answer by OperationDogBird · Aug 11, 2012 at 09:43 AM

rigidbody.constraints can only be compared to RigidbodyConstraints.

So if you want to check if all are true, you would say something like

 if(rigidbody.constraints==RigidbodyConstraints.FreezeAll)print("Frozen");

same thing for all the other RB Constraint values.

Also, in an if statement you need to say && not &.

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 Razion · Aug 13, 2012 at 09:26 PM 0
Share

Ah, brilliant. That did the trick. Thanks!

avatar image
2

Answer by AlexMiller12 · Aug 15, 2015 at 01:08 AM

The marked solution is actually a little dangerous. If you want to know if the X axis is frozen, you may get undesirable behavior if other axes are frozen as well.

 rigidbody.constraints = RigidbodyConstraints.FreezeAll;
 bool isXFrozenBad = ( rigidbody.constraints == RigidbodyConstraints.FreezePositionX );
 bool isXFrozenGood = ( rigidbody.constraints & RigidbodyConstraints.FreezePositionX ) != RigidbodyConstraints.None;

 // isXFrozenBad is false, isXFrozenGood is true




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 btsai · Jul 22, 2016 at 05:22 AM 0
Share

I was thinking about how to test for an individual constraint regardless of others, this is exactly what I needed. Thanks!

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

10 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

Related Questions

How do I query the RigidbodyConstraints? 3 Answers

Is it possible to constrain an object's rotation in worldspace? 2 Answers

UnityEngine.Rigidbody does not contain a definition for `contraints' 1 Answer

Pause GameObject motion 1 Answer

Constraining Rigidbody to Spline 4 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