• 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 Crossroad1000 · Nov 04, 2015 at 09:28 PM · getcomponentfreezefreezepositionfreezerotation

Freeze Rigidbody

Hi, I want to make a script so that i can freeze the X, Z rotation and the Z position. But when I attach the script to my gameObject it won't work.

Here is the script so far.

 var target : Transform;
 function Start () {
 }
 function Update () {
 
 }
 function OnTriggerEnter (col : Collider) {
 
 if(col.gameObject.tag == "mijnobject") {
 GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX;
 GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
 yield WaitForSeconds(0.1);
 this.GetComponent.<ConstantForce>().force = Vector3.right * 60;
 this.GetComponent.<Rigidbody>().useGravity = false;
 GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.None;
 GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionZ;
 GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX.FreezeRotationZ;
 
         }
     }
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
6
Best Answer

Answer by Mako-Infused · Nov 04, 2015 at 09:52 PM

You're setting the constraint equal to different values sequentially. The "constraints" property is a flagged enum value (or bitmask), as such you have to combine the constraints into a single value using bit operations. For example when you want to set the constraint to freezing the position of both the X & Y axis, you can do this:

  GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY;

Hopefully my example makes sense, if not definitely check out the provided link!

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 Crossroad1000 · Nov 04, 2015 at 10:15 PM 0
Share

Thanks! :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

32 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

Related Questions

Freeze players position and rotation for a time? 0 Answers

Temporarily freezing the player (Standard Asset FPS Controller) 1 Answer

How to freeze an object when collision? 4 Answers

How can I simulate a thread? 1 Answer

Unity 5.4.0b14 freezes in editor 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges