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 Toxic Blob · Apr 18, 2011 at 09:40 PM · rigidbodyfreezeconstraintsfreezeposition

How do I query the RigidbodyConstraints?

How can I query the rigidbody.constraints? I want to determine if certain objects have RigidbodyConstraints.FreezePositionY enabled.

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

3 Replies

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

Answer by Eric5h5 · Apr 18, 2011 at 09:44 PM

See the docs. If you're trying to see if the constraints contain FreezePosition.Y among other values, rather than just checking to see if they are FreezePosition.Y, then you can mask it with &:

if (rigidbody.constraints & RigidbodyConstraints.FreezePositionY) {
    // constraints has at least FreezePositionY, don't care about others 
}
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 Toxic Blob · Apr 18, 2011 at 10:27 PM 0
Share

I have. Unfortunately the docs discuss setting the constraints, but not how to read which constraints are set - though it might just be me being thick, so if so, please do let me know how I can read the constraint settings

avatar image Eric5h5 · Apr 19, 2011 at 12:36 AM 0
Share

@Toxic Blob: wait, are you just checking for FreezePositionY or do you want to see if FreezePositionY is one of the constraints even though there might be others? The former should be obvious from the docs, the latter maybe not so obvious.

avatar image Toxic Blob · Apr 19, 2011 at 02:20 PM 0
Share

That's exactly what I was attempting to do. That solution wasn't exactly obvious. Thanks for the help! Superb!

avatar image
1

Answer by Jean-Fabre · Mar 29, 2016 at 08:37 AM

Hi,

here's what works for me ( http://stackoverflow.com/a/19590373/178302)

 if((rigidbody.constraints & RigidbodyConstraints.FreezePositionX) == RigidbodyConstraints.FreezePositionX) 
 {
     // x-position is frozen
 }

Bye,

Jean

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
0

Answer by scamp · Sep 29, 2013 at 12:06 AM

Eric5h5's solution no longer works (in C#, anyway). Here's an up-to-date version:

     using System;
     using UnityEngine;
     
     public static class RigidbodyConstraintExentions
     {
         public static bool HasConstraint(this RigidbodyConstraints thisConstraint, RigidbodyConstraints constraint)
         {
             return (thisConstraint & constraint) != RigidbodyConstraints.None;
         }
     }
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 God-at-play · Jun 07, 2014 at 10:31 PM 0
Share

This isn't working for me. Did it change again?

 if ((rigidbody.constraints & RigidbodyConstraints.FreezeRotationZ) != RigidbodyConstraints.None)
 {
     Debug.Log("Rotation frozen");
     euler.z = 0f;
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

holding position 1 Answer

JS - How do I change the constraints of an object? 1 Answer

Disabling rigidbody constraints in code - Freeze Position, Rotation etc 7 Answers

RigidbobyConstraints2D is not working in Unity 5.0.2f1 Personal Edition!! 0 Answers

Query Rigidbody Constraints? 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