08-08-2022, 02:56 PM
(08-08-2022, 02:24 PM)josemendez Wrote: If you wanted to get rid of this, you would need to teleport all particles in the rope to a new position and not just the ends (placing them in a straight line from Origin transform to End transform is a good idea). Also set all particle velocities to zero to remove any unwanted velocity from the previous use of the rope.
Hi again!
Ok, I did it and it almost worked 100%!
The attachment, position and motion are now fine, but, for some reason, the end point is sometimes being dettached. Here you can see this:
https://streamable.com/d1ticx
Here's how the code is:
Code:
public void Connect(Transform origin, Transform end)
{
cursor.ChangeLength((end.position - origin.position).magnitude);
for (var i = 0; i < rope.elements.Count; i++)
{
ObiStructuralElement element = rope.elements[i];
float t = (float)i / (float)rope.elements.Count;
Vector3 position = Vector3.Lerp(origin.position, end.position, t);
int particleIndex1 = element.particle1;
int particleIndex2 = element.particle2;
rope.solver.positions[particleIndex1] = position;
rope.solver.positions[particleIndex2] = position;
rope.solver.velocities[particleIndex1] = Vector4.zero;
rope.solver.velocities[particleIndex2] = Vector4.zero;
}
attachment1.enabled = true;
attachment2.enabled = true;
attachment1.target = origin;
attachment2.target = end;
}
public void Disconnect()
{
attachment1.target = null;
attachment2.target = null;
attachment1.enabled = false;
attachment2.enabled = false;
}
Once again, sorry for bothering you so much but thank you for the amazing support!