- Home /
Problem assigning hj.connectedBody
Hi, I'm having a further problem with my ragdoll script. I drop this script onto each bone in a ragdoll and it sets it all up for me. I can't get the hingejoint parameters setting correctly. It refuses to assign the connectedbody, anchor position etc. I've tried putting it in the update() function and it seemingly works fine.
var manParentBone:GameObject;
var manJointObject:GameObject;
var manBoneWeight:float;
var manIsEndBone:boolean;
@HideInInspector //hides var below from the inspector
var testbool:boolean = true;
function Start () {
if (manBoneWeight==0) // check to make sure the bone has weight
{
Debug.Log (gameObject.name+" has zero weight, setting to 1.");
manBoneWeight=1;
}
var rb=gameObject.AddComponent (Rigidbody);
var mc=gameObject.AddComponent (MeshCollider);
rb.mass = manBoneWeight;
mc.convex = true;
if (manIsEndBone==false) // Does the bone have parents? If so, make a hinge connection to the parent.
{
var hj=gameObject.AddComponent (HingeJoint); //create hinge
hj.connectedBody = manParentBone.rigidbody; //connect hinge
hj.anchor = manJointObject.transform.position-gameObject.transform.position;
hj.useLimits = true; //use hinge limits
hj.limits.min = 5;
hj.limits.max = -5;
}
}
function Update () {
}
As well as not being able to set the anchor inside the start() function, when I do set the anchor it seems to be wrong. If I want to set the position of the anchor to the manJointObject, then I just minus the manJointObject position from the bone. This should give me the position of the joint relative to the bone, right?
Thanks in advance for your help, I really appreciate it.
Your answer
Follow this Question
Related Questions
Problems with 2d ragdoll 1 Answer
Anchor at connectedbody 1 Answer
How to calculate the anchor point location, when 2 meshes join by a hinge joint 1 Answer
Hinges in an imported mesh 0 Answers
Hinge Joint strange behaviour 0 Answers