如何在代码中动态更改布料约束? Unity 3d

时间:2018-01-14 00:09:47

标签: c# unity3d

好吧,所以我有一个胶囊,当它与布料发生碰撞时,我希望布料粘在胶囊上,我可以选择约束并用新值替换它们。我遇到麻烦的是当它与布料碰撞时,胶囊离布料最近的约束。我认为它与胶囊对撞机的接触点有关?

基本上,我试图制作" tape"。我可以用布料碰撞,但是当我将胶囊移回原位时,我需要将布料粘在上面。

Video of what I have so far

void OnCollisionEnter(Collision col) 
{
    Rigidbody colRb = col.gameObject.GetComponent<Rigidbody>();
    colRb.isKinematic = true;

    //------------------------------------------------------------------------
    Vector3 contactPoint = col.contacts[0].point; //the location of where the collision is on the col 

    for (int i = 0; i < newConstraints.Length; i++)
    {
        if(contactPoint == tape.vertices[i])
        {
            //I need to only select the indices that are near the contactPoint, not all of them as in this case with i
            newConstraints[i].maxDistance = 0;
            tape.coefficients = newConstraints;
        }

    }

}

0 个答案:

没有答案