Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Hot to get Mu out of raycast info
#2
(25-11-2021, 05:32 AM)Hlibs Wrote: Hi
I've been using raycasting to find specific point on obi rope where the player is watching and can get it's index and position
Can I get normalized position mu out of it somehow?

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,
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 josemendez - 25-11-2021, 08:39 AM
RE: Hot to get Mu out of raycast info - by Hlibs - 25-11-2021, 10:19 AM