Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tear after changing length with cursor
#2
Your code is incorrect:

You're indexing the solver.particleToActor array using a simplex index. You need to use a particle index instead. Check the manual to see how to retrieve a particle index from a simplex: http://obi.virtualmethodstudio.com/tutor...sions.html

In case you're not using surface collisions, you can do:

Code:
int particleIndex = solver.simplices[contact.bodyA];

Then, you can do:

Code:
ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];

However this last bit is not necessary: you don't need to know the index in the actor to tear an element, see below:

You're also indexing the elements array with a particle index:
Code:
actor.Tear(actor.elements[pa.indexInActor]);

If this works, is just pure luck, as most often will result in an out of bounds exception. You need to determine which element in the elements array references your particle, and tear that. Iterate over all elements until you find an element such that element.particle1 = particleIndex, then use that element.


Wrapping up, the code should be:

Code:
// find particle for this simplex:
int particleIndex = solver.simplices[contact.bodyA];

// find an element that references this particle, and tear it.
foreach (var elm in rope.elements)
if (elm.particle1 == particleIndex)
rope.Tear(elm);

// rebuild constraints
rope.RebuildConstraintsFromElements();
Reply


Messages In This Thread
RE: Tear after changing length with cursor - by josemendez - 13-05-2021, 02:54 PM