Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resetting rope end positions when attaching the rope
#1
Hello again, after studying the documentation I realized that when I change the target in ObiParticleAttachment the particle remain in the positions they were, however now the ParticleGroup is bound to a different transform.

This causes problems as I need to attach the end of the rope to a clearly marked location, instead it only binds to attachment position without resetting its own.
Reply
#2
(01-08-2023, 02:23 PM)Alexander34 Wrote: Hello again, after studying the documentation I realized that when I change the target in ObiParticleAttachment the particle remain in the positions they were, however now the ParticleGroup is bound to a different transform.

This causes problems as I need to attach the end of the rope to a clearly marked location, instead it only binds to attachment position without resetting its own.


Hi,

You can just set the position of the particle to whatever location you need it to be before creating the attachment, as suggested in the docs:

Quote:If you want particles attached at a specific position other than their position at the time of creating the attachment, you can set their position at runtime before creating the attachment: see scripting particles.

Note that this might lead to unphysical behavior, since you're essentially teleporting a part of the rope around.

let me know if you need further help,

kind regards
Reply
#3
(01-08-2023, 03:46 PM)josemendez Wrote: Hi,

You can just set the position of the particle to whatever location you need it to be before creating the attachment, as suggested in the docs:


Note that this might lead to unphysical behavior, since you're essentially teleporting a part of the rope around.

let me know if you need further help,

kind regards
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?
Reply
#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
#5
(02-08-2023, 07:16 AM)josemendez Wrote: 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;
its worked, thanks. It's worked too with
Code:
_obiRope.TeleportParticle(particleIndex, position);
Reply
#6
(02-08-2023, 04:11 PM)Alexander34 Wrote: its worked, thanks. It's worked too with
Code:
_obiRope.TeleportParticle(particleIndex, position);

Hi!

TeleportParticle() does some additional work (resetting particle interpolation) but in most cases it’s equivalent to the code above.

Cheers,
Reply