Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Resetting Rope causing Error
#11
(07-08-2024, 12:15 PM)josemendez Wrote: Just realized there's an issue with both the above code and yours (in both Obi 6 and 7): it's not waiting for the rope to be actually loaded by the solver. So when called several times in a row the rest length may not be the length reflected in the blueprint, but the previous length of the rope. Won't cause any runtime errors, but the resulting length of the rope may not be correct.

Simply waiting for the rope to be loaded before changing its length fixes this:

Code:
using UnityEngine;
using Obi;
using System.Collections;

public class ResetRope : MonoBehaviour
{
    public float initialLength = 3;
    public ObiRope rope;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
            StartCoroutine(Reset());
    }

    public IEnumerator Reset()
    {
        rope.RemoveFromSolver();
        rope.ClearState();
        rope.AddToSolver();

        while (!rope.isLoaded)
            yield return new WaitForEndOfFrame();

        rope.GetComponent<ObiRopeCursor>().ChangeLength(initialLength - rope.restLength);
    }
}


Thanks, this one actually resolved the issue
Reply