- Home /
Question by
AaronDuke · Apr 22, 2016 at 07:37 PM ·
hingejointconnectedbody
How do i Instantiate multiple game objects with Hinge joints that have there Connected body to the previous Instantiated game object?
So i have a rope game object with the Instantiated as children of the rope game object, but how can i set the connected body of the Instantiated hinge joints to the previous Instantiated object so its like rope?
for example;
rope: Instantiated 1 Instantiated 2 Instantiated 3 how do i set the 3rd Instantiated object connected body to the 2nd Instantiated object and the 2nd Instantiated object connected body to Instantiated object 1?
using UnityEngine; using System.Collections;
public class Rope : MonoBehaviour {
public int ropeLength;
public GameObject ropeSegment;
GameObject[] length;
public Vector3 ropeSegmentLoc;
Rigidbody cloneRb;
public int segmentNumber;
Rigidbody connectedRbBody; // the connected body for the segment joints
HingeJoint c;
int connectedbody;
void Start () {
GameObject[] spawned = GameObject.FindGameObjectsWithTag("rope"); // Instatiated segments with tag
length = new GameObject[ropeLength];
for ( int i = 0; i < length.Length; i++){
GameObject clone = (GameObject) Instantiate(ropeSegment, ropeSegmentLoc, Quaternion.identity); // clones ropeSegment
clone.transform.parent = this.transform; // sets the parent of the clone to the base
cloneRb = clone.GetComponent<Rigidbody>(); // clones rigidbody
c = cloneRb.hingeJoint; // clones hingeJoint
segmentNumber ++;
clone.name = segmentNumber.ToString(); // sets the name of each Instantiated ropeSegemnt clone to a number
length[i] = ropeSegment;
//Debug.Log(i);
}
Comment
Your answer
Follow this Question
Related Questions
Anchor at connectedbody 1 Answer
Problem assigning hj.connectedBody 0 Answers
Hinges in an imported mesh 0 Answers
Hinge Joint strange behaviour 0 Answers