25-02-2020, 04:35 PM
(This post was last modified: 25-02-2020, 04:47 PM by josemendez.)
(25-02-2020, 04:09 PM)TheMunk Wrote: Thanks - got me a bit further although not the entire way.
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;
}
}
But it looks like the velocities stops updating after some time even though the rope is still moving (see here):
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.
Hi,
It's hard to tell, but in your video the highest velocity seems to stop updating right when the rope particles stop moving. Isn't this the expected result?
Also, multiplying velocities by the delta time converts them to position deltas. I'm not sure if this is intended, but most likely not. Velocities are expressed in meters/second, so you don't need to multiply them by anything (unless you want to use a threshold expressed in meters, but then it wouldn't be independent of the timestep)
Edit: I just realized that you might have copied the "actor.solver.velocities[solverIndex] * Time.fixedDeltaTime" from the documentation. I did this because the sample visualizer draws a line between two positions (the particle position, and the position where it will move to the next frame, due to its velocity) so I need to integrate velocity over time to get a position, hence the * Time.fixedDeltaTime. Remember from basic physics that velocity = distance/time, so distance = velocity * time. You don't want to work with distances but with velocities.