Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Part of rope Tense
#5
This is what I thought too. But still the rope even when not tense , returns value >1. Am I missing something ?

Code:
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_;
    }
}
Reply


Messages In This Thread
Part of rope Tense - by tpaslou - 17-03-2021, 03:55 PM
RE: Part of rope Tense - by josemendez - 18-03-2021, 09:36 AM
RE: Part of rope Tense - by tpaslou - 18-03-2021, 12:47 PM
RE: Part of rope Tense - by josemendez - 18-03-2021, 01:39 PM
RE: Part of rope Tense - by tpaslou - 18-03-2021, 02:29 PM
RE: Part of rope Tense - by josemendez - 18-03-2021, 02:34 PM
RE: Part of rope Tense - by tpaslou - 18-03-2021, 02:59 PM
RE: Part of rope Tense - by josemendez - 18-03-2021, 03:09 PM