07-06-2024, 08:04 AM
Hi,
I've attached video reference here of what happened while trying to cut the rope.
I've used RopeSweepCut. Its working in the sample scene. But If I use the same script for my Rope which is created dynamically at runtime, it not working.
When I swipe to cut, I can see the line renderer and on release, there's a shake happening in rope but its not actually cutting the rope.
I added log inside the below function. Log printed as expected but cut doesn't work
https://drive.google.com/file/d/1EqPp-hm...sp=sharing
I've attached video reference here of what happened while trying to cut the rope.
I've used RopeSweepCut. Its working in the sample scene. But If I use the same script for my Rope which is created dynamically at runtime, it not working.
When I swipe to cut, I can see the line renderer and on release, there's a shake happening in rope but its not actually cutting the rope.
I added log inside the below function. Log printed as expected but cut doesn't work
https://drive.google.com/file/d/1EqPp-hm...sp=sharing
Code:
private void ScreenSpaceCut(Vector2 lineStart, Vector2 lineEnd)
{
// keep track of whether the rope was cut or not.
bool cut = false;
// iterate over all elements and test them for intersection with the line:
for (int i = 0; i < rope.elements.Count; ++i)
{
// project the both ends of the element to screen space.
Vector3 screenPos1 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle1]);
Vector3 screenPos2 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle2]);
// test if there's an intersection:
if (SegmentSegmentIntersection(screenPos1, screenPos2, lineStart, lineEnd, out float r, out float s))
{
cut = true;
rope.Tear(rope.elements[i]);
Debug.Log("cut");
}
}
// If the rope was cut at any point, rebuilt constraints:
if (cut) rope.RebuildConstraintsFromElements();
}