- Home /
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?
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?
Your answer
Follow this Question
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