19-04-2023, 07:43 AM
(This post was last modified: 19-04-2023, 07:44 AM by josemendez.)
(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):
Component enabled:
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