23-09-2020, 08:38 AM
Hey there, thanks for the reply.
I've read the article (should have mentioned it I suppose xD), and I can indeed tangle the ropes, but the ropes move from their attachments and return to them a frame later.
Here's the code for storing the positions (I store them in a scriptable object)
And here is the code that applies the stored position
Ropes Tangle.PNG (Size: 55.28 KB / Downloads: 30)
Ropes Tangle
Ropes return.PNG (Size: 27.73 KB / Downloads: 30)
Ropes Return to attachments
I've read the article (should have mentioned it I suppose xD), and I can indeed tangle the ropes, but the ropes move from their attachments and return to them a frame later.
Here's the code for storing the positions (I store them in a scriptable object)
Code:
void StoreRopeParticles(GameObject rope)
{
List<Vector3> particlePos = new List<Vector3>();
ObiActor actor = rope.GetComponent<ObiActor>();
int solverIndex;
for (int i = 0; i < actor.particleCount; i++)
{
solverIndex = actor.solverIndices[i];
particlePos.Add(actor.GetParticlePosition(solverIndex));
}
RopeParticlePosition newRope = new RopeParticlePosition(rope, particlePos);
ropePositionsSO.StoreData(newRope);
}
And here is the code that applies the stored position
Code:
void InitializeParticles(RopePositionsSO particlesPosition)
{
foreach (RopeParticlePosition positions in particlesPosition.ropePositions)
{
if(positions.ropeID == RopeID)
{
ObiActor actor = GetComponent<ObiActor>();
int solverIndex;
for (int i = 0; i < actor.solverIndices.Length; i++)
{
solverIndex = actor.solverIndices[i];
actor.solver.positions[solverIndex] = positions.particlePositions[i];
}
}
}
}
Ropes Tangle.PNG (Size: 55.28 KB / Downloads: 30)
Ropes Tangle
Ropes return.PNG (Size: 27.73 KB / Downloads: 30)
Ropes Return to attachments