Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
End of the rope! Match position
#11
Quote:Hi, so if you imagine a rope, with three particleAttachments, each with a unique particleGroup, where index 0 is left, index 1 is middle and index 2 is the right end of the rope.

I want to know the position that is, index 2.

You can use the code I just shared with you. Just set the groupIndex variable to the index of the group you're interested in.

Code:
var group = rope.blueprint.groups[groupIndex]; // in your example you'd set groupIndex to 2.
int particleIndex = rope.solverIndices[group.particleIndices[0]];
var position = rope.solver.transform.TransformPoint(rope.solver.positions[particleIndex]); // this would be the position you're looking for.

This would also work, in cases where the attachment is at the end of the rope:

Code:
int lastParticle = rope.elements[rope.elements.Count-1].particle2;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[lastParticle]);

Or start of the rope:

Code:
int firstParticle = rope.elements[0].particle1;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[firstParticle]);

The only difference between both methods is that you get the particle index from the rope itself, instead of getting it from the blueprint's particle groups. Once you have the correct particle index, retrieving the position is done the exact same way.
Reply
#12
Lovely!!Solved.
Thanks.
Reply