Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi Rope How To Get Any Position From Rope
#6
Still unable to reproduce it, only thing I can think of is that you're calling this method when the rope is not even initialized yet (such as the Awake() or Start() of a separate object, called by Unity before the rope's).

If that is the case, simplest workaround is to just wait for the first frame to end before calling this coroutine. For instance:

Code:
IEnumerator Start()
    {
        yield return new WaitForEndOfFrame();
        StartCoroutine(FlowEffect());
    }

On a side note, your code has a problem:
Code:
while (mu < obiRope.CalculateLength())

mu is a normalized coordinate, that ranges from 0 (start of the rope) to 1(end of the rope). Comparing it against the rope length (which is expressed in meters) doesn't make much sense. If you want to sweep the entire rope, use while(mu < 1).

Sample component that fixes both issues:

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

public class Test : MonoBehaviour
{

    public ObiRope obiRope;
    public Transform rastgeleBirKup;

    IEnumerator Start()
    {
        yield return new WaitForEndOfFrame();
        StartCoroutine(FlowEffect());
    }

    private IEnumerator FlowEffect()
    {
       
        ObiPathSmoother pathSmoother = obiRope.GetComponent<ObiPathSmoother>();
        float mu = 0;
        while (mu < 1)
        {
            mu += 0.01f;
            ObiPathFrame pos = pathSmoother.GetSectionAt(mu);
            rastgeleBirKup.localPosition = pos.position;
            yield return new WaitForSeconds(0.005f);
        }
        StartCoroutine(FlowEffect());
    }
}
Reply


Messages In This Thread
RE: Obi Rope How To Get Any Position From Rope - by josemendez - 17-01-2022, 08:28 PM