How to Free ConfigurableJoint?

Hello. Can anybody help me, please? I want my platform fall when will be hit by a beam. My script is attached to trigger inside the platform:

var Beam : GameObject; var Platform : GameObject; var joint : joint = Platform.GetComponent(ConfigurableJoint);

function Start(){ Beam = GameObject.Find("Beam"); Platform = GameObject.Find("Platform"); }

function OnTriggerEnter (other : Collider) { if(other.transform.name == "Beam"){ print("HIT"); joint.ConfigurableJointMotion.Free; } }

?? :)

Hi,

the lock/limited/free setting of a joint is in my opinion and current knoweldge not really appropriate for this kind of use,

If you are using a configurable joint because you just want to hold the platform in place and just let it fall at a later time, you can simply use the fixedJoint instead

http://unity3d.com/support/documentation/Components/class-FixedJoint.html

also look at the breakforce property of the joint, if you set that to 0, it will break loose under its own weight.

1: create a cube

2: add a fixedJoint to it

3: play

4: set the breakforce to that fixedjoint to 0, and see the cube falling

-- notice that the fixedjoint component disappear, don't worry it comes back when you hit stop

-- also notice that by default, if you don't specify a connected body on the joint, it attach itself to the world where it currently is.

-- the benefit from using breakforce is that you can really create advanced platform behavior and possible have the platform fall under the weight of the player or your beam, simply set the breakforce appropriatly. You can be informed of a break using OnJointBreak()

5: to script this create a new javascript and attach it to the cube

function Update () {

    if ( Input.anyKeyDown){

        var theJoint:FixedJoint = GetComponent(FixedJoint);

        if (theJoint != null){
            Debug.Log("Breaking the joint");
            theJoint.breakForce = 0;
        }else{
            Debug.Log("the joint if already broken");
        }

    }

}

function OnJointBreak(breakForce : float) {
    Debug.Log("I have just been broken!, force: " + breakForce);
}

Hope this helps,

Jean

A Joint can only be used to connect two rigidbodys in a certain way. With the ConfigurableJoint you can specify rotation limits and movement limits.

It sounds like you want to create a kind of an elevator-platform. Just move the platform with the Transform- component. If a player or other rigidbodys should be able to travel with the platform it's better to use a kinematic rigidbody. If you take a look at the Lerpz demo tutorial project, there is such a platform implemented.

A little hint on your script: It's good practise to obtain references at start and use this refs in Update() to reduce the frame time. But your script have a little bug ;)

You should do something like:

// The script instance is created before Start() is called
var Beam : GameObject;
var Platform : GameObject;
var joint : joint;

function Start() {
   Beam = GameObject.Find("Beam");
   Platform = GameObject.Find("Platform");
   joint = Platform.GetComponent(ConfigurableJoint)
}

If you assign your platform GO in the inspector you don't need to use GameObject.Find()!