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
0
Question by ina · Nov 12, 2012 at 06:08 AM · rigidbodyconstraintsbitwise

Bitwise OR vs AND for combining rigidbody constraints

Why is the bitwise OR and not AND used to combine rigidbody constraints?

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-constraints.html

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

Answer by phodges · Nov 12, 2012 at 06:45 AM

This is fundamental to how these boolean operators work. Each constraint is a separate bit. Consider the following example, written in binary:

myConstraint1 = 01 myConstraint2 = 10

If I was to apply the bitwise AND operator to these constraints I would get nothing (01 & 10 = 0). If I was to apply the bitwise OR operator to them, I would collect both bits (01 | 10 = 11) and so this is equivalent to requiring that both constraints be respected. This merged mask is then checked by later code to see which constraints should be applied, using an AND operation to pick out specific items, i.e.

mergedConstraints & myConstraint1

If this test is non-zero then I know that the constraint should be applied.

Comment
Add comment · Show 3 · 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 ina · Nov 12, 2012 at 09:24 AM 0
Share

does this continue to work for N bits? and not just 2 ?

avatar image phodges · Nov 12, 2012 at 09:24 AM 0
Share

Of course, up the limit of the type you are using.

avatar image aldonaletto · Nov 12, 2012 at 10:42 AM 1
Share

Use bitwise OR (|) to turn a bit on:

 mergedConstraints = myConstraint1 | myConstraint2;

In order to turn some bit off, AND it to the negated mask. If you want to clear myConstrant1, for instance, do this:

 mergedConstraints &= ^myConstraint1;

Never use + or - to set/clear bits: if the bit is already in the desired state, other bits will be affected.

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

How do I query the RigidbodyConstraints? 3 Answers

Rigidbody Freeze Contraints Not Working 2 Answers

rigidbody constraints no longer part of unityscript or something? 2 Answers

Query Rigidbody Constraints? 2 Answers

Disabling Rigidbody constraints on GameObject that script is attached to 3 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