Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Oscillations when setting cable lengths, probably due to dynamics
#2
1.- Just in case: make sure all ropes are part of the same solver and the same updater, since they're involved in the same simulation. Otherwise they will behave independently, calculating and applying forces as if no other ropes were attached to the rigidbody.

2.- You're assuming the rope is kinematic and has no momentum, so it cannot stretch or compress due to inertia. I'd recommend to leave some room for the rope to expand/contract a bit, like so:

Code:
if (c2_len > c2_control_ip + room)
        {
            cursor_2.ChangeLength(rope_2.restLength - c2_control_ip * time_dt/10);
        }

        else if(c2_len < c2_control_ip - room)
        {
            cursor_2.ChangeLength(rope_2.restLength + c2_control_ip * time_dt/10);
        }

Otherwise if the rope stretches or compresses even a little bit, it will trigger a change in rest length.  This is similar to what the included sample ObiRopeReel script does:

Code:
// Update is called once per frame
void Update()
{
    // get current and rest lengths:
    float length = rope.CalculateLength();
    float restLength = rope.restLength;

    // calculate difference between current length and rest length:
    float diff = Mathf.Max(0, length - restLength);

    // if the rope has been stretched beyond the reel out threshold, increase its rest length:
    if (diff > outThreshold)
        restLength += diff * outSpeed;

    // if the rope is not stretched past the reel in threshold, decrease its rest length:
    if (diff < inThreshold)
        restLength -= diff * inSpeed;

    // set the new rest length:
    cursor.ChangeLength(restLength);
}
Reply


Messages In This Thread
RE: Oscillations when setting cable lengths, probably due to dynamics - by josemendez - 29-03-2023, 09:45 AM