10-02-2025, 12:09 PM
(This post was last modified: 10-02-2025, 12:18 PM by josemendez.)
(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.