Create HingeJoint by script

i was trying to make HingeJoint between 2 pole in horizontal
direction by script but the joint act like not as i expected it doesn’t swing at all

private HingeJoint tempHinge;

void OnCollisionEnter(Collision coll)
        foreach(ContactPoint c in coll.contacts)
            tempHinge = coll.gameObject.AddComponent<HingeJoint>();
            tempHinge.connectedBody = coll.gameObject.rigidbody;

You have to make sure the anchor and the axis parameter.
anchor and axis are showed with yellow arrow.

this is just a sample parameter, you have to change this with your own
parameter depends on your gameobject position

// place the anchor to wherever you like
tempHinge.achor = new Vector3(2.0f, -0.5f, 0f)

// swing direction
tempHinge.axis = new Vector(0,0,1);