Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Rest Length" returns unexpected values
#1
Pregunta 
I've set up a rope that is completely linear - the start point, end point and tangents are all in a straight line.

I've temporarily removed the [HideInInspector] tags on the field "ObiRopeBlueprintBase.m_RestLength" so I could see its value. Looking at the code, it appears to represent the total length of all the segments in the rope as measured from the distances between connected particles. However, the rest length value displayed was very off.

The start and end points were exactly 2m apart, but the rope's reported rest length was reported to be 42!
On top of that, changing the resolution will cause the rest length to change anywhere between 202 (at a resolution of 0) and 6.878044 (at a resolution of 1).

I looked through the code can't make sense of why it'd come up with wildly unexpected values on a linear rope. Even if the rope was curved, the length should increase with resolution, not decrease.

Is it measuring the length of the rope relative to something else?
Reply
#2
rope.restLength returns the rest length of the rope in meters. It's just the accumulated distance from each particle in the rope to the next one, as you describe.

Did a quick test of a straight 2 meter rope, and restLength always returns 2. This is the code and the results:

Code:
void Update()
    {
        Debug.Log(GetComponent<ObiRope>().restLength);
    }

[Image: yoqJk9p.png]

Changing the resolution does not affect it at all (since the rope is completely straight, there's no way it could affect the outcome!). In a curved rope increasing resolution will slightly increase the rest length, as the discretization is finer. Never had any bug reports regarding this, should just work as it's very simple stuff.

Can you share more details about what you're doing? How are you generating the rope? How are you getting the rest length?

Quote:The start and end points were exactly 2m apart, but the rope's reported rest length was reported to be 42!

Having the start and end points 2 meters apart from each other does not guarantee the rope to be 2 meters long. Depending on what the input/output tangents of the control points are, the rope could be much larger or smaller, as you can have a much longer curve with lots of particles that just happen to be collinear.
Reply
#3
You can reproduce it in the project I sent you for the previous bug.

In a new empty scene:

  1. Drag the prefab "Assets/ObiPrefabs/Rope" into the scene and center it on 0,0,0.
  2. Create a cube and position it at 1,0,0. Change its scale to 1,2,1. This can be used to compare sizes. It is at least approximately 2.
  3. Add "Debug.Log(m_RestLength);" at the end of ObiRopeBlueprint.Initialize().
  4. Select the rope and click "Edit Path" on the Obi Rope inspector.
  5. Wiggle around the control points of either end of the rope.
  6. Observe that something around "42" is displayed in the console.

I've done the same thing and took a screenshot:

I cannot seem to upload an image more than 100kb on this forum.

Maybe this will work: 
https://i.imgur.com/cf0BlxY.jpg

But anyway, I've intentionally bowed out the rope a bit so that you can see the tangents are not causing the rope to fold over itself. It should be only a little more than 2 even with that slight bend.

Alternate theory: this rope has gained sentience and is trying to explain the meaning of life to us.
Reply
#4
You're measuring the blueprint's rest length. The default rope blueprint has 100 pooled particles. That's a blueprint rest length of roughly 2/5*100 = 40 meters, so the reported value is correct.

If you want to get the runtime rest length, use rope.restLength as I did in the snippet above. That will give you the rest length of the currently active particles (that might change if you use a cursor to resize the rope, as this activates/deactivates particles from the pool).


Quote:I cannot seem to upload an image more than 100kb on this forum.
Attachment size is capped to keep hosting costs reasonable. You can upload them to imgur or some other website and paste the link here.

Quote:Alternate theory: this rope has gained sentience and is trying to explain the meaning of life to us.

Kudos for the reference Sonrisa. But sadly we'll have to wait for Deep Thought to be built, these ropes aren't quite there yet.
Reply
#5
(20-05-2021, 05:50 PM)josemendez Wrote: You're measuring the blueprint's rest length. The default rope prefab has 100 pooled particles. That's a blueprint rest length of roughly 2/5*100 = 40 meters, so the reported value is correct.

If you want to get the runtime rest length, use rope.restLength. That will give you the rest length of the currently active particles.


Attachment size is capped to keep hosting costs reasonable. You can upload them to imgur or some other website and paste the link here.

I'm trying to instantiate a rope that follows the given curve, but then the tightness of the rope can be adjusted by setting its overall rest length to the distance between the two connected points, scaled by some factor. This needs to be done in the blueprint if my understanding is correct.

Originally I tried just scaling the rest distances inside the blueprint by some factor during the Generate() steps, but if the rope curved, it'd be longer than the distance between the two points and not taut.

I thought then, I could make the rope not curve, by setting the tangents somewhere colinear with the start and end points. But the tangents of the path endpoints are set to the normals of the surfaces they are attached to. This way, when the rope is loose, it'd try to keep the rope's ends parallel with their attach points' surface normals.

So, I went with calculating the ratio between the current length measured in the blueprint and the desired length (euclidean distance between the two attach points) deand scaling the rest distances by that ratio. (restLength *= desiredOverallRestLength / currentOverallRestLength). But then noticed the rope was getting very small.

Is there some way to know what the actual rest length of the rope will be in the blueprint generation phase?
Reply
#6
(20-05-2021, 06:09 PM)Hatchling Wrote: Is there some way to know what the actual rest length of the rope will be in the blueprint generation phase?

Code:
GetComponent<ObiRope>().ropeBlueprint.path.Length;

This will return the exact length of the path used to generate the rope.
Reply
#7
(20-05-2021, 06:16 PM)josemendez Wrote:
Code:
GetComponent<ObiRope>().ropeBlueprint.path.Length;

This will return the exact length of the path used to generate the rope.

Thanks! I have a feeling that this will return the length of the path (via some sort of integration along the curve) and not the length of the rope that approximates the path... butttt... it's probably close enough.
Reply
#8
(20-05-2021, 07:31 PM)Hatchling Wrote: Thanks! I have a feeling that this will return the length of the path (via some sort of integration along the curve) and not the length of the rope that approximates the path... butttt... it's probably close enough.

Yep, returns an as-tight-as-possible approximation of the actual curve length using Gauss-Lobatto quadrature.

I can add a method to get the particle-based length if you need it. Let me know if the path length doesn’t suffice!
Reply