13-02-2020, 01:11 PM
(13-02-2020, 12:18 PM)basilisk Wrote: I have a coiled rope that unwinds nicely when the rope is enabled. I want to have the rope reset to it's starting coiled shape every time I activate it. How to I reset the rope to it's original shape?
All you need to do is set the solver's particle positions/velocities to the ones stored in the blueprint. If you're using a rod (which makes use of oriented particles), do the same with particle orientations/angular velocities.
Only thing you need to be a bit careful with is converting the blueprint data (which is expressed in local space) to solver space. Like this:
Code:
void Reset(ObiActor actor)
{
if (actor.isLoaded)
{
Matrix4x4 l2sTransform = actor.actorLocalToSolverMatrix;
Quaternion l2sRotation = l2sTransform.rotation;
for (int i = 0; i < actor.particleCount; ++i)
{
int solverIndex = actor.solverIndices[i];
actor.solver.positions[solverIndex] = l2sTransform.MultiplyPoint3x4(actor.blueprint.positions[i]);
actor.solver.velocities[solverIndex] = l2sTransform.MultiplyVector(actor.blueprint.velocities[i]);
if (actor.usesOrientedParticles)
{
actor.solver.orientations[solverIndex] = l2sRotation * actor.blueprint.orientations[i];
actor.solver.angularVelocities[solverIndex] = l2sTransform.MultiplyVector(actor.blueprint.angularVelocities[i]);
}
}
}
}
See:
http://obi.virtualmethodstudio.com/tutor...icles.html