06-07-2023, 10:31 AM
(06-07-2023, 10:25 AM)josemendez Wrote: Ok, where during the update cycle are you doing this? Update, FixedUpdate, one of the solver callbacks...? You'd typically want to set these values in the solver's OnEndStep callback. Copying them at any other time may lead to the solver modifying these positions as part of its normal simulation cycle. The idea is that you want both solvers to have finished a simulation step, and copy their particle values before rendering takes place.
Also, make sure to copy previousPositions array and startPositions arrays. These are used to derive velocities and perform interpolation, respectively.
Unless you're explicitly writing custom data in ExternalForces and ExternalTorques, these values will always be zero. As the name implies, they're "external" to the simulation.
The source code is contained in a coroutine. It is initially called from Start() and repeats every 0.1 seconds using recursion.
private void Start()
{
if (isReceive)
{
StartCoroutine(Co_WaitUpdate());
}
}
private IEnumerator Co_WaitUpdate()
{
yield return new WaitForSeconds(0.1f);
for (int i = 0; i < actor.solverIndices.Length; ++i)
{
rope.solver.positions[actor.solverIndices[i]] = otherRope.solver.positions[actor.solverIndices[i]];
rope.solver.velocities[actor.solverIndices[i]] = otherRope.solver.velocities[actor.solverIndices[i]];
}
StartCoroutine(Co_WaitUpdate());
}