Trying to create character joint, but object zooms away instead.
I am trying to make feet stick to a surface and require a certain amount of force to detach. So far I am trying to do this by creating a characterjoint on the ground when the foot hits, hoping that this joint will allow it a little angular wiggle while it is stuck. However, the second time the foot touches the surface it goes flying off in the same direction each time, gaining a lot of positive x y and z force. Anybody know why it would do this?
Here's the basics of what I'm doing. Groundlock is the characterjoint being created.
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == ground.name)
{
if(groundlock==false)
{
gameObject.AddComponent<CharacterJoint>();
gameObject.GetComponent<CharacterJoint>().connectedBody = col.rigidbody;
groundlock = GetComponent<CharacterJoint>();
ContactPoint contact = col.contacts[0];
vectAnchor = new Vector3(0, -1, 0); // these coordinates are for the bottom of the foot
groundlock.autoConfigureConnectedAnchor = false;
groundlock.anchor = vectAnchor;
groundlock.connectedAnchor = contact.point;
groundlock.breakForce = 10;
}
}
}
Comment