- Home /
AddComponent(HingeJoint) bug!
I was adding a hinge joint in runtime but then the object acts weird. It barely or almost does not rotate! I made sure the limit is deactivated.
I have this prefabed car that has lots of skin mesh and collider children that will detach from car every time it crashes. It had a trigger collider to detect crashes and the AddComponet is inside my OnTrigger function. I dont see how this would affect my hinge joint. I tried to make 2 new cube objects, stick them with the hinge joint on an update function and it worked. I tried to put a hinge joint manually in the inspector for my car and it worked fine. I tried to put the AddComponent in the Update function for the car this time and the bug still happens.
I'm now certain their's a bug in my car but I ran out of ideas where the bug could be.
Anyone encountered this bug? How can I get rid of the bug?
Here's my OnTrigger function activating the AddComponent:
function OnTriggerStay (collision : Collider)
{
if (gforce > 0.3 && timer > 100)
{
if (anim1) anim1.animation[anim1.animation.clip.name].speed = 5;
timer = 0;
animTimer = 0;
panelPicker = Random.Range(0,1);
if ( panel1 )
{
if(panel1.hingeJoint && panelPicker == 0)
{
panel1.transform.parent.parent = null;
panel1.collider.enabled = true;
panel1.hingeJoint.breakForce = 0;
panel1Detach = true;
}
else if ( !panel1.hingeJoint && panel1Detach == false && panelPicker == 0 )
{
panel1.gameObject.AddComponent(HingeJoint);
panel1.hingeJoint.connectedBody = car;
panel1.hingeJoint.useLimits = false;
}
}
can't paste all the codes caouse i reach character limit.
Your answer