25-07-2024, 06:01 PM
(This post was last modified: 25-07-2024, 06:05 PM by josemendez.)
(25-07-2024, 05:28 PM)Ferhat123 Wrote: Thank you for your answer.
I tried your suggestion. I'm encountering a strange situation as shown in the video I shared.
https://drive.google.com/file/d/1Bd3HLS5...sp=sharing
As shown in the video, there is a yellow cylinder that is already attached. After cutting, I attach one cylinder to the end of the rope fixed to the wall and another cylinder to the beginning of the falling piece.
Here is my code:
Code:private void ScreenSpaceCut(Vector2 lineStart, Vector2 lineEnd)
{
// keep track of whether the rope was cut or not.
bool cut = false;
int leftParticles = -1;
int rightParticle = -1;
// iterate over all elements and test them for intersection with the line:
for (int i = 0; i < rope.elements.Count; ++i)
{
// project the both ends of the element to screen space.
Vector3 screenPos1 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle1]);
Vector3 screenPos2 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle2]);
// test if there's an intersection:
if (SegmentSegmentIntersection(screenPos1, screenPos2, lineStart, lineEnd, out float r, out float s))
{
leftParticles = rope.elements[i].particle1;
rightParticle = rope.elements[i].particle2;
cut = true;
rope.Tear(rope.elements[i]);
}
}
// If the rope was cut at any point, rebuilt constraints:
if (cut)
{
rope.RebuildConstraintsFromElements();
obiTest.AddNewSolidModel(leftParticles, rightParticle);
}
}
Code:public void AddNewSolidModel(int leftParticle, int rightParticle)
{
AttachSolidModel(leftParticle, "Left");
AttachSolidModel(rightParticle, "Right");
}
private void AttachSolidModel(int particle, string groupName)
{
var go = Instantiate(solidModel);
go.transform.position = rope.solver.positions[particle];
go.transform.rotation = transform.rotation;
var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
group.particleIndices.Add(particle);
group.name = groupName;
var particleAttachment = gameObject.AddComponent<ObiParticleAttachment>();
particleAttachment.particleGroup = group;
particleAttachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
particleAttachment.target = go.transform;
}
Hi,
Ropes only consider particle positions, not rotations/orientation. Only rods consider rotation.
How are you attaching the first cylinder to the rope? The only way to do this in a rope is to use two attachments, as that removes two rotational degrees of freedom (only one line passes trough two points in space). If this is what you’re doing for ths first cylinder, you should follow the same method for the dynamically attached cylinders.
Kind regards,