# How change cloth anchor points dynamically through code?

I’m trying to make cloth sticky, like tape. I have a collider that when it collides with the cloth I can change all of the anchor points but not the ones that are near where the collider collides with the tape. I[109330-tapeexample.png*|109330]f there’s an alternate approach I’m all ears.

``````void OnCollisionEnter(Collision col)
{

Vector3 contactPoint = col.contacts.point;
for (int i = 0; i < newConstraints.Length; i++)
{

/* I need to only select the indices that are near the contactPoint, not all of them as in this case with i */
newConstraints*.maxDistance = 0;*
``````

tape.coefficients = newConstraints;

}
}
*

I did something similar a while back. In my code, when I iterate through each constraint, I check whether the contact point is close to the each vertex on the cloth, and then set the constraint based on that. So something like this:

``````    void OnCollisionEnter(Collision col) {

Vector3 contactPoint = col.contacts.point;

for (int i = 0; i < newConstraints.Length; i++)
{
// Transform the vertex position to world space
Vector3 transformedVertex = cloth.transform.TransformPoint(cloth.vertices*);*
``````

// Check if the contact point and the vertex’s position are approximately equal
if (Approximately(contactPoint, transformedVertex))
{
newConstraints*.maxDistance = 0;*
}

tape.coefficients = newConstraints;

}
}
You’ll need to write your own approximately function for Vector3. Mine just checks whether the x, y, and z components are similar to each other within a given tolerance.
I hope this helps!