Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope stretch problem
#1
Hello, I am making a rope length real-time update project, encountered some problems, I hope I can get help
Below is the method to dynamically change the length of the rope, which is performed in the Update, which cannot be changed。
Code:
public void ChangeRopeLength()
{
    restLength = Rope.restLength;
    currentLength = Rope.CalculateLength();
    diff = currentLength - restLength;

    if (diff > m_StretchThre)
        restLength += diff * Time.deltaTime * m_StretchSpeed;

    if (diff < m_ShortenThre)
        if (restLength > startLength)
            restLength += diff * Time.deltaTime * m_ShortenSpeed;

    m_RopeCursor.ChangeLength(restLength);

    ropeLength = Rope.restLength;

    //m StretchThre is 0.1,m_ShortenThre is -0.1,m_StretchSpeed and m_ShortenSpeed is 50.
}
This method only works if I set the value of Distance Constraints to 0.5 or less. If I set it to 1, the rope will stretch indefinitely. Even if I changed the m StretchThre in the top code to be large enough, it wouldn't work as well as I wanted.
I wonder what method I can use to change the rope length in Update when I change the Distance Constraints to 1,So that the length of the rope can be normal variation, rather than infinite elongation
Reply
#2
Hi!

Increasing the amount of substeps should work. This will increase simulation quality - reducing spurious stretching, a much better alternative to setting stretching scale to 0.5.

For an in-depth explanation of how substeps/iterations affect results, see:
http://obi.virtualmethodstudio.com/manua...gence.html
Reply
#3
(19-03-2024, 07:28 AM)何塞门德斯 Wrote: 你好!增加子步骤

的数量应该有效。这将提高模拟质量 - 减少虚假拉伸,这是将拉伸比例设置为 0.5 的更好替代方案。有关子步骤/迭代如何影响结果的深入说明,请参阅:http ://obi.virtualmethodstudio.com/manual/6.3/convergence.html[url=http://obi.virtualmethodstudio.com/manual/6.3/updaters.html][/url]
您好,感谢您的回复,但是我的场景中可能有很多绳子,我担心增加子步骤数量会导致性能问题
Reply
#4
(19-03-2024, 07:33 AM)Agony Wrote: 您好,感谢您的回复,但是我的场景中可能有很多绳子,我担心增加子步骤数量会导致性能问题

Obstacles/colliders in the scene are not affected by substeps. Collision detection is only performed once per frame, regardless of the amount of substeps used. Only constraint solving and integration are performed once per substep, so unless you have extremely long ropes (or many ropes), increasing the amount of substeps should be fine.
Reply
#5
(19-03-2024, 08:35 AM)josemendez Wrote: Obstacles/colliders in the scene are not affected by substeps. Collision detection is only performed once per frame, regardless of the amount of substeps used. Only constraint solving and integration are performed once per substep, so unless you have extremely long ropes (or many ropes), increasing the amount of substeps should be fine.
Ok, one more question, can I dynamically change the mass of every particle in the rope?
Reply
#6
(19-03-2024, 09:24 AM)Agony Wrote: Ok, one more question, can I dynamically change the mass of every particle in the rope?

Yes, you can change any particle property at runtime. See:
http://obi.virtualmethodstudio.com/manua...icles.html
Reply