Obi Official Forum
Help Add force to particle - 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: Help Add force to particle (/thread-2522.html)



Add force to particle - flaurens - 05-10-2020

Hi!

I have the next scenario:

One ObiSolver that contains a few ropes. What I want is that once I cut one of that ropes (using the ObiRope.Tear function), I want to apply a certain amount of force to each extreme of the particles in order to add some juice to the cut action.

In the past, I was using ObiSolver.externalforces, using as an index the element that contains the particle that I get from e.contacts (being e ->ObiSolver.ObiCollisionEventArgs). At that time I was using One ObiSolver per rope so there wasn't any problem.

Now I'm using one ObiSolver for different ropes. Is there any way to get the global number of the element that contains the particle?
Because if I'm using the old way the force is applied to a different rope than the one that I'm tearing it.

Regards!


RE: Add force to particle - josemendez - 05-10-2020

Don't pass an element index to the solver arrays, as elements != particles. This won't work if there is more than one actor in the solver, and won't work in the general case of resized/torn ropes. If it worked before, it's just luck.

Rope elements contain the indices of both particles at its ends, you should be able to use that.

Code:
solver.externalForces[element.particle1] = <your force>;
solver.externalForces[element.particle2] = <your force>;