Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resetting rope end positions when attaching the rope
#4
(01-08-2023, 06:04 PM)Alexander34 Wrote: Yes, I couldn't find specific examples in Scripting Particles. Can you specifically tell me how, from the code, I can firmly attach one end of the rope to the necessary Transform so that it visually appears attached rather than just repeating the position of the connected object?

Hi!

All it takes is writing the position you want the rope to be attached to in the solver.positions array, at the correct index. Here's some sample code:

Code:
// disable the attachment:
attachment.enabled = false;

// retrieve the index of the attached particle, and set its position (converting from world to solver space as required):
int particleIndex = rope.solverIndices[attachment.particleGroup.particleIndices[0]];
rope.solver.positions[particleIndex] = rope.solver.transform.InverseTransformPoint(MyObject.transform.position);

// set the new attachment's target:
attachment.target = MyObject.transform;

// re-enable the attachment:
attachment.enabled = true;
Reply


Messages In This Thread
RE: Resetting rope end positions when attaching the rope - by josemendez - 02-08-2023, 07:16 AM