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?