Hello,
I managed to save and reload particle positions in ObiRope v6.x using code under the Copy ropes in play mode thread. However, this no longer works in ObiRope v7.x. Could you help me identify what I might be missing?
Here’s my current code:
The save sections look like this:
Thanks!
I managed to save and reload particle positions in ObiRope v6.x using code under the Copy ropes in play mode thread. However, this no longer works in ObiRope v7.x. Could you help me identify what I might be missing?
Here’s my current code:
Code:
public void Load(Vector3[] particlePositions, Vector3 lastParticlePosition)
{
int particleCount = particlePositions.Length;
while (rope.activeParticleCount > particleCount)
{
rope.elements.RemoveAt(rope.elements.Count - 1);
rope.DeactivateParticle(rope.activeParticleCount - 1);
}
while (rope.activeParticleCount < particleCount)
{
rope.elements.Add(new ObiStructuralElement
{
particle1 = rope.elements[^1].particle1,
//maybe this should be so:
//particle2 = rope.elements[^1].particle2,
particle2 = rope.solverIndices[rope.activeParticleCount],
restLength = rope.interParticleDistance
});
rope.CopyParticle(rope.activeParticleCount - 1, rope.activeParticleCount);
rope.ActivateParticle(); // This doesn't have an actorIndex anymore.
}
for (int j = 0; j < rope.elements.Count; ++j)
{
int firstParticle = rope.elements[j].particle1;
rope.solver.positions[firstParticle] = particlePositions[j];
rope.solver.velocities[firstParticle] = Vector4.zero;
rope.solver.angularVelocities[firstParticle] = Vector4.zero;
}
int lastParticle = rope.elements[^1].particle2;
rope.solver.positions[lastParticle] = lastParticlePosition;
rope.solver.velocities[lastParticle] = Vector4.zero;
rope.solver.angularVelocities[lastParticle] = Vector4.zero;
rope.RebuildConstraintsFromElements();
}
The save sections look like this:
Code:
int positionCount = rope.elements.Count;
Vector3[] particlePositions = new Vector3[positionCount];
for (int j = 0; j < positionCount; ++j)
{
particlePositions[j] = rope.solver.positions[rope.elements[j].particle1];
}
Vector3 lastParticlePosition = rope.solver.positions[rope.elements[positionCount - 1].particle2];
Thanks!