25-11-2021, 10:19 AM
(25-11-2021, 08:39 AM)josemendez Wrote: Hi there!Along the rope, yes
Do you mean normalized coordinate along the raycast, or along the rope? Also, are you using surface collisions?
Along the raycast, mu = result.distance / maxDistance;
Along the rope, assuming you use surface collisions the raycast query returns the index of the simplex hit. You have to traverse a couple data structures to get the mu along the rope:
- Get the particle indices of the simplex:
Code:int simplexStart = solver.simplexCounts.GetSimplexStartAndSize(result.simplexIndex, out int simplexSize);
int firstParticle = solver.simplices[simplexStart];
int secondParticle = solver.simplices[simplexStart+1]; // always 2 particles in a rope simplex.
- Look for the rope element that references these particles, and once you find it just divide its index by the amount of elements:
Code:for (int i = 0; i < rope.elements.Count; ++i)
{
if (rope.elements[i].particle1 == firstParticle && rope.elements[i].particle2 == secondParticle)
return i / (float)rope.elements.Count;
}
You could get a finer result by considering the hit position along the current element's length, and adding that to the resulting mu value.
kind regards,
Thank you, it's working great now!