19-03-2024, 07:13 AM
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。
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
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.
}
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