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 fracticality · Nov 30, 2020 at 05:23 PM · gravityinput.getkey

Setting RigidBody.Constraints to None isn't reapplying Gravity

Rudimentary 'falling block' game. Two sprites currently, both with position and rotation 'frozen' in the RigidComponent2D. Gravity scale for both objects set to 1.

Goal: Pressing a key causes the block to fall.
Method: Keypress detected in Update() call, set block's RigidComponent2D constraints to 'None'. Result: Constraints are removed (confirmed by checking Inspector), but block doesn't fall.

Notes: If done without a keypress, block falls. If done by toggling 'freeze y' position in Inspector, block also falls.
What am I missing?

 private Rigidbody2D _rigidBody;
 // Start is called before the first frame update
 void Start()
 {
     _rigidBody = GetComponent<Rigidbody2D>();
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.Space)) {
         //_rigidBody.constraints = RigidbodyConstraints2D.FreezePositionX;
         _rigidBody.constraints = RigidbodyConstraints2D.None; //this gets called, but doesn't trigger the gravity to 'apply'
     }
       _rigidBody.constraints = RigidbodyConstraints2D.None; //this does work though
 }

Comment
Add comment · Show 3
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 Owen-Reynolds · Nov 30, 2020 at 06:30 PM 0
Share

Try going to scene mode and manually moving the block a little. If it falls then, it was probably because the block was "asleep" and removing constraints didn't wake it up.

avatar image fracticality · Nov 30, 2020 at 11:03 PM 0
Share

What would cause the object to be 'asleep' and how does one 'wake it up'?

avatar image fracticality · Nov 30, 2020 at 11:17 PM 0
Share

I figured it out, thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fracticality · Nov 30, 2020 at 11:16 PM

Figured it out, thanks to @Owen-Reynolds!

The RigidBody2D component has a Sleeping mode property.
From the documentation (https://docs.unity3d.com/ScriptReference/Rigidbody2D-sleepMode.html):

"Sleeping is an optimisation that is used to temporarily remove an object from physics simulation when it is at rest. This property chooses whether the rigidbody should start off asleep, awake or have sleeping turned off altogether."

alt text

To resolve, I just had to change the Sleeping mode to 'Never Sleep': alt text


1.png (108.0 kB)
2.png (104.4 kB)
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

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

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

Best way to keep an ai grounded? 1 Answer

Jumping Stopped Working. 2 Answers

Bike wobbles like pendulum after applying gravity 1 Answer

Js: UnityEngine.Rigidbody is required, how to fix? 2 Answers

How to set gravity for model? 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