- Home /
Question by
franklynw · Nov 18, 2011 at 12:27 PM ·
hingejointanchor
How to pick up a chain of objects
Hello,
I'm trying to get my player to pick up objects which then line up behind him in a flexible chain, which will swing around as he moves. I can pick up and get the objects to be attached to each other, but I can't line them up behind him. I'm a bit new to Unity & C# (coming from obj-c) so any help much appreciated! Code (on the player gameObject) -
private IList<GameObject> bubbles = new List<GameObject>();
private int bubbleCount = 0;
void OnCollisionEnter(Collision theObject) {
GameObject theGameObject = theObject.gameObject;
if (theGameObject.tag == "Bubble") {
if (theGameObject.hingeJoint.connectedBody == null) {
if (bubbleCount == 0) {
theGameObject.hingeJoint.connectedBody = gameObject.rigidbody;
// how to set the bubble's position here?
} else {
GameObject lastBubbleObject = bubbles[bubbleCount - 1];
theGameObject.hingeJoint.connectedBody = lastBubbleObject.rigidbody;
theGameObject.hingeJoint.anchor = lastBubbleObject.transform.position;
// need to attach it to the last object in the line
}
bubbles.Add(theGameObject);
bubbleCount ++;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Visual Way to Set Anchor Points in Hinge Joint 2D 2 Answers
Problem assigning hj.connectedBody 0 Answers
Anchor at connectedbody 1 Answer
No 2d hinge joint lines 1 Answer
Problems with 2d ragdoll 1 Answer