Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by EstherDevs · Nov 11, 2016 at 11:27 AM · c#movementrigidbodyconstraints

Error CS0201 when trying to change RigidbodyConstraints

Hello there! My game has a ball that rolls when you use the arrow keys, however I want it to stop rolling once you release the arrows keys so it doesn't roll of the edge.

I'm using Rigidbody.Constraints to constrain the X and Z axys so it stops rolling, but it will still fall to it's doom when it is rolled over the edge.

I'm using the following code, but it's giving me an error CS0201 for the 4th, 8th and 9th line.

     if (movement != Vector3.zero) {
         rb.AddForce (movement * speed);
         if (RigidbodyConstraints.FreezePositionX && RigidbodyConstraints.FreezePositionZ) {
             RigidbodyConstraints.None;
         }
     } else {
         if (RigidbodyConstraints.None) {
             RigidbodyConstraints.FreezePositionX;
             RigidbodyConstraints.FreezePositionZ;
         }
     }


What am I doing wrong here and how could I improve my code?

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 Landern · Nov 11, 2016 at 02:22 PM

It's because you're not assigning anything, you're just calling various enumerations of type RigidbodyConstraints. What you're looking for i would assume is to Change the rb(Your rigidbody) constraints. To add addition context, if i was driving down the road and just said "HOTDOG!" it's possible the other people in the car would have an exception to this statement since it would make no sense; did i want a hotdog? did i see a got dog? However if i would say, "That car looks like a hotdog" then the other people would think i've set a attribute/characteristic of a hotdog. Kinda the same thing here(i stress kind of), but just saying RigidbodyConstraints.None(or any other options of the enum) doesn't affect anything or using an if statement with the enum isn't doing anything, it's not comparing something to something, its just like saying Hotdog out of the blue.

I would adjust your code to compare(assuming i'm correct) the rb.constraints variable, you will need to use bitwise operations(sorry, this topic can get confusing for the uninitiated) to compare combined bit values of the enum of type RigidbodyConstraints.

The change:

 if (movement != Vector3.zero) {
          rb.AddForce (movement * speed);
          if ((rb.constraints & RigidbodyConstraints.FreezePositionX & RigidbodyConstraints.FreezePositionZ) == RigidbodyConstraints.FreezePositionX & RigidbodyConstraints.FreezePositionZ) {
              rb.constraints = RigidbodyConstraints.None;
          }
      } else {
          if (rb.constraints = RigidbodyConstraints.None) {
              rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
          }
      }

In .net 4.0 this can be further simplified by using the Enum.HasFlags method which checks for flags, this will make things easier to read.

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

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

Jump is higher then normal 0 Answers

How to make Rigidbody movement not slippery? 4 Answers

Stopping Moving Objects? 0 Answers

,Why is my character sliding? (Rigid Body) 0 Answers

Why is my character sliding? (Rigid Body) 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