Obi Official Forum
End of the rope! Match position - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: End of the rope! Match position (/thread-3965.html)

Pages: 1 2


RE: End of the rope! Match position - josemendez - 16-08-2023

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.


RE: End of the rope! Match position - Renman3000 - 17-08-2023

Lovely!!Solved.
Thanks.