(25-02-2020, 12:35 PM)josemendez Wrote: Hi,Thanks - got me a bit further although not the entire way.
Elements are a logic "connection" between two particles. You don't need to use them at all, not for your purpose. They're mostly used to change the topology of the rope, when resizing a rope or tearing it.
You have several examples of particle iteration in the manual:
http://obi.virtualmethodstudio.com/tutor...icles.html
In your particular case, you only have one actor (rope) per solver, so it does not really matter if you iterate over the actor's solverIndices array, or over the solver data arrays directly. So you could either do what's done in the manual:
Code:// Iterate over all particles in an actor:
for (int i = 0; i < actor.solverIndices.Length; ++i){
// retrieve the particle index in the solver:
int solverIndex = actor.solverIndices[i];
// look up the particle velocity:
if (actor.solver.velocities[solverIndex] ...etc)
{
}
}
or
Code:// Iterate over all particles in the solver:
for (int i = 0; i < actor.solver.velocities.Length; ++i){
// look up the particle velocity:
if (actor.solver.velocities[i] ...etc)
{
}
}
This last method will only work correctly if there's exactly one actor in the solver, though. As you add/remove actors from a solver, particles are reassigned to different actors and the actor's solverIndices array is the only consistent way to access solver data arrays. (You can think of Obi as an ECS system, where particles are entities, and the constraint groups are components.)
So all that's left to do is check if the velocity magnitude of each particle is over a threshold. If you find that all particles are under the threshold, you can disable the solver.
I'm doing this on Fixed Update;
Code:
highestParticleMagnitude = 0;
highestVelocity = new Vector4(0, 0, 0, 0);
// Iterate over all particles in an actor:
for (int i = 0; i < rope.solverIndices.Length; ++i)
{
// retrieve the particle index in the solver:
int solverIndex = rope.solverIndices[i];
// look up the particle velocity:
if ((rope.solver.velocities[solverIndex] * Time.fixedDeltaTime).magnitude > highestVelocity.magnitude)
{
highestVelocity = (rope.solver.velocities[solverIndex] * Time.fixedDeltaTime);
highestParticleMagnitude = rope.solver.velocities[solverIndex].magnitude;
}
}
As you can see the VelocityVisualizer from your documentation seems to work fine though, so why isn't mine updating?
Changing sleep threshold in the solver doesn't help.
EDIT:
It seems to work right until I shorten the rope, then it breaks... Without errors.