top of page

ぶつかったオブジェクト同士がくっつく


    private CharacterJoint myJoint;

    // くっつく強さを設定
    public float force = 70;
    public float torque = 120;

    // 物体同士が触れた時の処理
    void  OnCollisionEnter (  Collision col   ){
        //Bulletならくっつき処理を行う
        if (col.gameObject.tag == "Player") {
            if (myJoint == null){

                myJoint = gameObject.AddComponent<CharacterJoint>() as CharacterJoint;
                myJoint.connectedBody = col.rigidbody;

                // 固定化の強さを指定する
                myJoint.breakForce = force;
                myJoint.breakTorque = torque;
            }
        }
    }

​※Rigidbodyを必ず付けること

bottom of page