Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Hot to get Mu out of raycast info
#3
(25-11-2021, 08:39 AM)josemendez Wrote: Hi there!

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,
Along the rope, yes
Thank you, it's working great now!
Reply


Messages In This Thread
Hot to get Mu out of raycast info - by Hlibs - 25-11-2021, 05:32 AM
RE: Hot to get Mu out of raycast info - by Hlibs - 25-11-2021, 10:19 AM