27-01-2022, 02:19 PM
(This post was last modified: 27-01-2022, 02:20 PM by josemendez.)
(27-01-2022, 02:08 PM)NorkQ Wrote: Actually I didn't understand what do you mean exactly. I tried the code below and it didn't work.
Code:float distance = Vector3.Distance(obiRope.GetParticlePosition(solverIndex), obiRope.GetParticlePosition(solverIndex - 1));
solver.principalRadii[solverIndex] = Vector3.one * (baseThickness + Mathf.Max(0, Mathf.Sin(distance + time) * bumpThickness));
You need to accumulate distance as you go, not just grab the distance between the current particle and the previous one. Otherwise the sine value will be basically the same for every particle, instead of varying along the rope.
Like this:
Code:
float distance = 0;
for (int i = 0; i < rope.solverIndices.Length; ++i)
{
int solverIndex = rope.solverIndices[i];
if (i > 0)
{
int previousIndex = rope.solverIndices[i - 1];
distance += Vector3.Distance(rope.solver.positions[solverIndex],rope.solver.positions[previousIndex]);
}
rope.solver.principalRadii[solverIndex] = Vector3.one * (baseThickness + Mathf.Max(0, Mathf.Sin(distance * bulgeScale + time) * bulgeThickness));
}
I threw a "bulgeScale" multiplier in there, so that you can control the width of the bulges.