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 /
This question was closed Aug 09, 2018 at 09:17 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
6
Question by CaptainIcy281 · Apr 12, 2012 at 02:50 AM · rigidbodyconstraintsfreezeposition

Can you unfreeze a rigidbody.constraint position as you can freeze them?

Yes, a simple question from me!

I want to freeze the rigidbody's Y position when the game is paused, as in my script:

if(GameManager.gamePaused == true) { transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY; }

And of course, when I unpause it I naturally want to unfreeze it. Is there a simple way to do that? I've looked around the various tutorials and Unity's scripting API pages, can't find anything about it.

Thanks!

Comment
Comments Locked · Show 1
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 GC1983 · Apr 12, 2012 at 03:08 AM 0
Share

I tested what you had and the only thing I could find was using RigidbodyConstraints.None;. This will turn all constraints off though. So if you dont have any of the other constraints on, then this will work perfectly for you. Otherwise, it looks that you can individually turn the other constraint on that you need that were turned off by that call.

2 Replies

  • Sort: 
avatar image
40
Best Answer

Answer by aldonaletto · Apr 12, 2012 at 03:21 AM

RigidbodyConstraints are bit masks, thus you can use + or | (bitwise OR) to set several constraints at once. To disable a single constraint, AND rigidbody.constraints with the negated mask (~):

   rigidbody.constraints &= ~RigidbodyConstraints.FreezePositionY;

But if you don't have other constraints active, just set rigidbody.constraints to RigidbodyConstraints.None:

   rigidbody.constraints = RigidbodyConstraints.None;
Comment
Comments Locked · Show 8 · 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 CaptainIcy281 · Apr 12, 2012 at 03:24 AM 0
Share

But see, I have all rigidbody Rotations disabled in the Inspector, so using Rigidbody.Constraints.None enables the rotation on unpause. I was hoping there was a simple way to just enable position.Y

I can use some other method I suppose, hmm.

avatar image Eric5h5 · Apr 12, 2012 at 03:37 AM 2
Share

He already explained the simple way to just use FreezePositionY. The constraints are bitmasks, so you turn on/off the bits you want.

avatar image CaptainIcy281 · Apr 12, 2012 at 03:40 AM 0
Share

Right, yeah, sorry. That works fine. Thanks, you two. ;)

avatar image harschell · Oct 26, 2012 at 05:46 AM 0
Share

hi can you tell me why this is not working whats Wrong here???? void getInput() { if (Input.GetButtonDown("Jump")) { rigidbody.constraints &= ~RigidbodyConstraints.FreezePositionY; flipGravity(); Debug.Log("gravity Flipped"); } }

avatar image aldonaletto · Oct 27, 2012 at 01:35 AM 0
Share

This code isn't enough to know what is going on. You should post a new question with the relevant part of your code: where rigidbody.constraints are set, show the function flipGravity() etc.

Show more comments
avatar image
6

Answer by gilley033 · Oct 15, 2013 at 08:31 PM

Another way to do this is to simply save the constraints in Awake or Start before changing them.

 var originalConstraints : RigidbodyConstraints;
 
 function Awake()
 {
      originalConstraints = rigidbody.constraints;
 }
 
 function FreezeConstraints()
 {
      rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
 }
 
 function UnFreezeConstraints()
 {
      rigidbody.constraints = originalConstraints;
 }
Comment
Comments Locked · 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

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

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

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

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

How do I query the RigidbodyConstraints? 3 Answers

Attempt to disable constraints using RigidbodyConstraints.None has no effect 0 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