Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Changing rope lenth creates erratic behaviour
#1
Hello!

Using Obi Rope, I'm trying to make a simple system where a rope is connected to a wall (attachment pin), and to an object that the player can control (another attachment pin); both of those static. I want to make sure that when the object moves away from the wall attachment, the rope gets longer, and when it gets closer, the rope gets shorter. I'm using a cursor, and I tried a few different solutions, but I couldn't get it to work. Here is the current code:

Code:
float dist = Vector3.Distance(obj.position, wallAttachment.position) * 1.2f;
if(dist - rope.restLength > 0.1f)
{
      objCursor.ChangeLength(Time.deltaTime * ropeSpoolSpeed);
}
else if(dist - rope.restLength < -0.1f)
{
      objCursor.ChangeLength(Time.deltaTime * -ropeSpoolSpeed);
}


The result is extremely chaotic, as you can see in this video : 

Am I missing something?

Also, along my experiences, I managed to make the rope shorter than zero, which results in an error spamming (in my opinion, it should not be possible), and also to crash Unity, probably by making it too long ? (I feel like there should also be a failsafe there).

Thank you!
Reply
#2
(10-02-2025, 09:46 AM)VAbert Wrote: Hello!

The result is extremely chaotic,
Am I missing something?

Hi!

As it's written, your script will cause the rope to oscillate between becoming larger and shorter than the distance between the object and the wall as it ignores the new length of the rope returned by ChangeLength (rope.restLength is only updated after the next FixedUpdate takes place). Here's a corrected version:

Code:
using UnityEngine;
using Obi;

public class Test : MonoBehaviour
{
    public float ropeSpoolSpeed = 10;
    public ObiRopeCursor cursor;
    public Transform wallAttachment;
    public Transform ropeAttachment;
    public ObiRope rope;

    private float currentLength;

    private void Start()
    {
        currentLength = rope.restLength;
    }

    // Update is called once per frame
    void Update()
    {
        float dist = Vector3.Distance(ropeAttachment.position, wallAttachment.position) * 1.2f;
        if (dist - currentLength > 0.1f)
        {
            currentLength = cursor.ChangeLength(Time.deltaTime * ropeSpoolSpeed);
        }
        else if (dist - currentLength < -0.1f)
        {
            currentLength = cursor.ChangeLength(Time.deltaTime * -ropeSpoolSpeed);
        }
    }
}

It also seems that no new particles are not being added to the rope, so it may be that the rope blueprint has not enough pooled particles. See: https://obi.virtualmethodstudio.com/manu...ursor.html

Quote:Increasing the length of a rope using ObiRopeCursor will use particles from the blueprint's particle pool. Ensure the pool is large enough (by setting the blueprint's "pooled particles" property) to achieve the desired maximum length. When decreasing the rope's length, unused particles will be returned to the pool.

You may prefer to use the included ObiRopeReel utility script. It will automatically increase/decrease rope length to keep strain (tension) inside a target range.

(10-02-2025, 09:46 AM)VAbert Wrote: Also, along my experiences, I managed to make the rope shorter than zero, which results in an error spamming (in my opinion, it should not be possible),

This is a bug, should not be possible to make it have negative length. I'm attaching a slightly corrected ObiRopeCursor.cs script, try replacing yours with it.

(10-02-2025, 09:46 AM)VAbert Wrote: and also to crash Unity, probably by making it too long ? (I feel like there should also be a failsafe there).

There's already a failsafe in place: as soon as your rope's blueprint runs out of pooled particles, the rope will become larger by increasing the distance between particles: no more particles will be added to the rope.


Attached Files
.cs   ObiRopeCursor.cs (Size: 10.7 KB / Downloads: 1)
Reply
#3
Thank you for the quick and detailed answer!

I did fix the rest length issue, but I'm afraid it was not the main problem... To be sure, I created a new obisolver, added your short rope preset, and added your custom script, it seems there is still an issue... Depending on where I put the obi cursor, it either doesn't spawn new particles (if the cursor is on the wall attachment, which makes most sense to me), or spawns them but doesn't simulate them (when the cursor is on the object)... Here is a video with the two configurations. I have the same result with your obiropereel script.




EDIT : Okay, it seems it was because the cursor must not be at the very end, but on the second particle, otherwiste I guess the attachment messes with it...
Reply
#4
(11-02-2025, 10:10 AM)VAbert Wrote: Thank you for the quick and detailed answer!

I did fix the rest length issue, but I'm afraid it was not the main problem... To be sure, I created a new obisolver, added your short rope preset, and added your custom script, it seems there is still an issue... Depending on where I put the obi cursor, it either doesn't spawn new particles (if the cursor is on the wall attachment, which makes most sense to me), or spawns them but doesn't simulate them (when the cursor is on the object)... Here is a video with the two configurations. I have the same result with your obiropereel script.




EDIT : Okay, it seems it was because the cursor must not be at the very end, but on the second particle, otherwiste I guess the attachment messes with it...

Hi,

The cursors’s “source mu” parameter determines which particle along the rope is copied when adding new particles to the rope. So if you leave it at either end (0 or 1) and the particle at that end is attached to something, the new particles copied from it will also be attached which may not be the desired outcome.

Kind regards,
Reply