17-03-2021, 03:55 PM
With regard to this post http://obi.virtualmethodstudio.com/forum...d-490.html , I would like to know if it is possible to test if a specific part of the rope is tense , for example the part between 2 control points
(17-03-2021, 03:55 PM)tpaslou Wrote: [ -> ]With regard to this post http://obi.virtualmethodstudio.com/forum...d-490.html , I would like to know if it is possible to test if a specific part of the rope is tense , for example the part between 2 control points
public float CalculateLength()
{
float length = 0;
if (isLoaded)
{
// Iterate trough all distance constraints in order:
int elementCount = elements.Count;
for (int i = 0; i < elementCount; ++i)
length += Vector4.Distance(solver.positions[elements[i].particle1],
solver.positions[elements[i].particle2]);
}
return length;
}
public void RecalculateRestLength()
{
restLength_ = 0;
// Iterate trough all distance elements and accumulate their rest lengths.
int elementCount = elements.Count;
for (int i = 0; i < elementCount; ++i)
restLength_ += elements[i].restLength;
}
(18-03-2021, 12:47 PM)tpaslou Wrote: [ -> ]I have made some modifications and the part appears to be mostly tense even when it's not. So I checked the indexes for which I am calculating the strain.
What does the elements array consist of ? My rope has 15 control points , but the rope.elements.count is 86.
public class RopeTensity : MonoBehaviour
{
[Header("Obi Rope Fields")]
[SerializeField]
private ObiSolver solver;
[SerializeField]
private ObiRope rope;
[Header("Points to check")][Tooltip("Use these values like a percentage")]
[SerializeField]
private int startPointIndex;
[SerializeField]
private int endPointIndex;
public float strain;
private void Update()
{
if (IsPartStreched())
Debug.Log("PART STRECHED!");
}
public bool IsPartStreched()
{
strain = CalculateLength() / CalculateRestLength();
Debug.Log(rope.elements.Count);
if (strain > 1)
return true;
else
return false;
}
private float CalculateLength()
{
float length = 0;
if (rope!=null)
{
// Iterate trough all distance constraints in order:
for (int i = startPointIndex; i < endPointIndex ; ++i)
length += Vector4.Distance(solver.positions[rope.elements[i].particle1],
solver.positions[rope.elements[i].particle2]);
}
return length;
}
private float CalculateRestLength()
{
float restLength_ = 0;
// Iterate trough all distance elements and accumulate their rest lengths.
for (int i = startPointIndex; i < endPointIndex; ++i)
restLength_ += rope.elements[i].restLength;
return restLength_;
}
}
(18-03-2021, 02:34 PM)josemendez Wrote: [ -> ]If your simulation doesn't perfectly converge (and I doubt it does, unless you're using hundreds of substeps/iterations), the result will always be larger than 1 under even the slightest external force/acceleration. A simple rope hanging under the force of gravity will have strain > 1.
What you probably want is to compare the strain to a threshold (eg 1.1, 1.2, etc). If the strain is over this threshold, then you consider the rope as "stretched".