Obi Official Forum
Normalized rope 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: Normalized rope position? (/thread-933.html)



Normalized rope position? - camirving - 25-02-2019

Hi there!

I have a rope and i've expanded its length.

I want to get the position of the particle that sits in the very middle of the rope, in normalized 0.5.

How can I retrieve a particle position via normalized value?


RE: Normalized rope position? - josemendez - 26-02-2019

(25-02-2019, 09:29 PM)camirving Wrote: Hi there!

I have a rope and i've expanded its length.

I want to get the position of the particle that sits in the very middle of the rope, in normalized 0.5.

How can I retrieve a particle position via normalized value?

Use rope.GetConstraintIndexAtNormalizedCoordinate(normCoord) to retrieve the index of the distance constraint at a given normalized coord (0,1). Then, you can choose a particle at either side of the constraint by using GetStructuralConstraintParticles(constraintIndex, ref particle1, ref particle2). The indices returned by this function are actor indices, convert them to solver indices using rope.particleIndices[] and you're done. Code:

Code:
int constraint = rope.GetConstraintIndexAtNormalizedCoordinate(0.5f);

int p1,p2;
rope.GetStructuralConstraintParticles(constraint, ref p1, ref p2);

// I chose the first particle in the constraint. You could get fancier by choosing the one that's closer to the normalized coord.
Vector3 position = rope.Solver.positions[rope.particleIndices[p1]];