Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Getting/Setting Particle Positions on Runtime
#3
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)
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];
            }
        }
        }
}

.png   Ropes Tangle.PNG (Size: 55.28 KB / Downloads: 30)
Ropes Tangle

.png   Ropes return.PNG (Size: 27.73 KB / Downloads: 30)
Ropes Return to attachments
Reply


Messages In This Thread
RE: Getting/Setting Particle Positions on Runtime - by Jackson - 23-09-2020, 08:38 AM