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 Jason Hamilton · Apr 24, 2011 at 08:20 AM · rigidbodyproconstraints

rigidbody constraints no longer part of unityscript or something?

Hey, Im using javascript or unityscript (whatever) and heres my code which, according to the documentation should stop movement of the rigidbody on the Z axis;

rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;

Now, when I put this into my script to didn't work, at all, those names (constraints, etc...) are recognised by the editor or something, have the names changed or something?

Im using unity 3.0.0f5 pro...

Comment
Add comment · 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 PaulTurowski · Oct 21, 2011 at 08:57 AM 0
Share

I'm also not able to get this bit of code to work and can't seem to find any answers online. When I run the script, I get a NullReferenceException, and even though I added a conditional testing for a NRE:

 if(rigidbody != null){
         rigidbody.constraints = RigidbodyConstraints.FreezeNone;
     } else {
         Debug.Log("rigidbody is null for some mysterious reason");
     }

I don't get my Debug message at all--just the same NR$$anonymous$$

Here's a simple script I made just for testing, which is attached to a basic object with a constraint of Z position (set in the Inspector).

function Start () { rigidbody.constraints = RigidbodyConstraints.FreezeNone; }

function Update () { rigidbody.AddForce(Vector3(0, 0, -5)); }

Same problem--NRE and the object doesn't move at all.

Any help would be greatly appreciated. Thanks.

2 Replies

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

Answer by save · Oct 21, 2011 at 10:15 AM

To clear things up a bit RigidbodyConstraints is an enumeration while constraints derived from Rigidbody is a variable. The constraints variable can take several layered values from the enumeration RigidbodyConstraints.

Doing this should freeze all motion on the Z-axis:

 rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;

To check if an object has a component named rigidbody use:

 if (rigidbody)

If the script isn't on the object use:

 if (theReference.rigidbody)

which for instance on a trigger could be:

 function OnTriggerEnter (other : Collider) {
     if (other.rigidbody)
 }

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 PaulTurowski · Oct 21, 2011 at 05:35 PM 0
Share

Thanks for the reply. $$anonymous$$y problem was a misunderstanding of how rigidbody.constraints works and I was able to get it to work correctly by putting it into Update() rather than Start().

So for anybody having similar issues, to remove a Z axis position constraint on an object, the script should be:


function Update () {
    rigidbody.constraints = RigidbodyConstraints.None;
    rigidbody.AddForce(Vector3(0, 0, -5));
}

note: It is RigidbodyConstraints.None, not RigidbodyConstraints.FreezeNone, as this page suggests. The link on said page needs to be corrected.

avatar image
0

Answer by PaulTurowski · Oct 21, 2011 at 09:19 AM

I'm also not able to get this bit of code to work and can't seem to find any answers online. When I run the script, I get a NullReferenceException, and even though I added a conditional testing for a NRE:

 if(rigidbody != null){
         rigidbody.constraints = RigidbodyConstraints.FreezeNone;
     } else {
         Debug.Log("rigidbody is null for some mysterious reason");
     }

I don't get my Debug message at all--just the same NRE.

Any help would be greatly appreciated. Thanks.

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

2 People are following this question.

avatar image avatar image

Related Questions

Disabling Rigidbody constraints on GameObject that script is attached to 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Detecting sudden changes in velocity? 1 Answer

Rotate object to face direction of movement 4 Answers

Remove rigidbody component 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