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 Alienjesus · Mar 06, 2011 at 05:58 AM · javascriptrigidbodydisableenableconfigurablejoint

Temporarily removing rigidbody and configurable joint and then replacing them

Hi guys, I'm making a game where I need to be able to pick up and move a gameobject without it being able to interact with the environment. To do this I need to remove or disable its rigidbody, in order to stop it colliding with other objects and to disable its gravity. However, because I'm making a 2D game, I also need to remove the objects configurable joint component temporarily to do this? How would I go about doing so? I cant figure out the code at all.

After I've moved the object, I need to be able to replace it, which also means I need to re-enable the configurable joint and rigidbody with exactly the same settings before, to prevent it being moved in the z axis for my 2d game. How would I do this in Javascript.

Here's my code for moving the objects so far. As you can see, it's pretty simple, because I'm quite new at this. When the controller object this script is attached to moves in front of the object I want to move, the object to be moved becomes a child of the controller.

function Update () {

var fwd = transform.TransformDirection (Vector3.forward); //Defining the travel direction of the raycast vector var hit : RaycastHit; var LayerMask = 1 << 9; //Interacts with Layer 9 - Moveable

//if Raycast finds a collider in front of this object in layer 9, print message 1, else print message 2. if (Physics.Raycast (transform.position, fwd, hit, 50, LayerMask)) { print ("There is something in front of the object!");
var otherThing = hit.transform;
otherThing.rigidbody.useGravity = false; otherThing.parent = transform; }

     else print ("Nothing in front of the object!");

}

So basically: 1.How can I disable rigidbodys and confiurable joints in code and 2. If I need to delete these components, whats the easiest way to recreate them in code?

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 Alienjesus · Mar 06, 2011 at 04:32 PM 0
Share

No-one? Please help, I need to figure this out. I've found the code to delete a rigidbody, but It won't let me because of the Configurable Joint. Would it work if it was a kinematic rigidbody?

0 Replies

· Add your reply
  • Sort: 

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

No one has followed this question yet.

Related Questions

Disable Rigidbody Function Start 1 Answer

Disable script from code 5 Answers

Can't remove Rigidbody from transform in script? 8 Answers

Disable C# Script from Java Script 1 Answer

Getting an objects Children 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