Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope Attachment on dynamic rope length and Stitching questions
#6
(18-04-2023, 12:45 PM)Balou Wrote: Same scene, same model, the one not working has been in the scene for quite a while. For now I'll replace it but I hope it doesn't happen again because it's annoying! 


What about this? Am I doing the right thing:


Thanks a lot.

Hi!

That looks (and works) just fine for me. Tried sewing a rope to a rod, added your code to a component and these are the results:

Component disabled (set stitch constraint relaxation to its minimum to exaggerate the gap):
[Image: Zt00VnD.png]

Component enabled:
[Image: 9Go8gs8.png]

This is the code I used:

Code:
using UnityEngine;
using Obi;

public class VisualGapBridge : MonoBehaviour
{
    public ObiRope rope;
    public ObiRod rod;

    void OnEnable()
    {
        GetComponent<ObiSolver>().OnInterpolate += VisualGapBridge_OnInterpolate;
    }

    void OnDisable()
    {
        GetComponent<ObiSolver>().OnInterpolate -= VisualGapBridge_OnInterpolate;
    }

    private void VisualGapBridge_OnInterpolate(ObiSolver solver)
    {
        int firstRopeParticle = rope.elements[rope.elements.Count-1].particle2;
        int lastRodParticle = rod.solverIndices[rod.solverIndices.Length - 1];
        Vector3 pos = solver.renderablePositions[lastRodParticle];
        solver.renderablePositions[firstRopeParticle] = pos;
    }
}

Note that depending on which ends you stitch together, you might want to use the last/first particle on either the rope or the rod. In my case I stitched the end of the rope to the end of the rod, so had to change:

Code:
rope.elements[0].particle1; // first particle

to

Code:
rope.elements[rope.elements.Count-1].particle2; // last particle
Reply


Messages In This Thread
RE: Rope Attachment on dynamic rope length and Stitching quesitons - by josemendez - 19-04-2023, 07:43 AM