Obi Official Forum
Resetting rope end positions when attaching the rope - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Resetting rope end positions when attaching the rope (/thread-3958.html)



Resetting rope end positions when attaching the rope - Alexander34 - 01-08-2023

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.


RE: Resetting rope end positions when attaching the rope - josemendez - 01-08-2023

(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


RE: Resetting rope end positions when attaching the rope - Alexander34 - 01-08-2023

(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?


RE: Resetting rope end positions when attaching the rope - josemendez - 02-08-2023

(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;



RE: Resetting rope end positions when attaching the rope - Alexander34 - 02-08-2023

(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);



RE: Resetting rope end positions when attaching the rope - josemendez - 02-08-2023

(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,