Help Apply force to a certain element of the rope - 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 Apply force to a certain element of the rope (/thread-2446.html) |
Apply force to a certain element of the rope - flaurens - 25-08-2020 Hi! I'm interested on knowing how to apply a certain force to a certain element of the rope. I let the player cut the rope by doing: Code: rope.Tear(rope.elements[IndexToBreak]); What I want is to apply a certain amount of force to IndexToBreak in order to simulate that the "cut" has been produced. Right now when the rope is cut it falls normally. I read from the documentation that I have to set the inverse mass of that element to zero and then apply the force that I want, but if I do that the element that I set its mass to zero gets freeze. What is the best approach in that case? Save the previous mass, set mass to zero, apply force and then set mass to the previous value? Regards! RE: Apply force to a certain element of the rope - josemendez - 25-08-2020 (25-08-2020, 11:53 AM)flaurens Wrote: Hi! Hi, First of all, elements and particles are not the same thing. An element is an "edge" linking two particles. You can't set any properties on an element, but you can set properties of any of the two particles at both ends. Now, to apply a force to a particle you can't set the inverse mass to zero. Setting the inverse mass to zero essentially deactivates physics, and allows you to directly set the position of a particle without dynamics modifying it. This is what the manual says: Quote:An inverse mass of 0 means the particle's mass is infinite, so its position will be unaffected by dynamics (allowing you to override it manually). A force however, does not directly affect the position of a particle. Remember that force = mass * acceleration. Just write the force vector in the solver.externalForces array at the indices indicated by the rope element. That should do it. RE: Apply force to a certain element of the rope - flaurens - 25-08-2020 (25-08-2020, 12:34 PM)josemendez Wrote: Hi,Ok I thank you that now I understand it a little bit better. But as I understand Tear is applied to an element right? How can I tear a rope starting from a collision? As I know from a collision callback I can get the particle... RE: Apply force to a certain element of the rope - josemendez - 26-08-2020 (25-08-2020, 07:22 PM)flaurens Wrote: Ok I thank you that now I understand it a little bit better. Hi, Yes, tearing is applied to elements. The logic behind tearing is that when an element detects that a large force would need to be applied to the particles at its ends to keep them together, one of the two particles is selected and duplicated to create a "gap" in the rope. Since collision detection you get the particle index, you simply need to look in the elements array for the first element that references that particle, and tear it. A simple for loop over all elements is the easiest way to do this. |